reading part of a string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

wish to take the following statement:

return " and wo3 = " + "'" + sysCodeList.SelectedItem + "'";

and read the sysCodeList.SelectedItem until there is a space in the string.

Does anyone know the code for doing that?

Thanks,

Dave
 
Dave,

You can't just concatenate sysCodeList.SelectedItem because it most
likely returns a ListViewItem (I'm assuming it is a ListView). You will
have to get the Text property of the item, and then use that, like this:

return " and wo3 = " + sysCodeList.SelectedItem.Text;

Hope this helps.
 
Depending on which control you are using, SelectedItem won't be a string, and
you'll
need to get to the string by using the appropriate member. Once you have that
do
the following (note I'm assuming ToString() on the selected item will work in
this case)


// Building intermediates to make the code more readable
string str = sysCodeList.SelectedItem.ToString();
int offset = str.IndexOf(" ");

// Returning your build string using a tenary operator
return " and wo3 = '" + ((offset == -1) ? str : str.Substring(0, offset)) + "'";
 
Back
Top