String Function

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

Guest

I need to read the contents of a dropdown listbox up to a space and then eliminate everything to the right of the space(including the space). How do I do this

Thanks

Dave
 
Dave,

The drop down list has an Items property which I believe you can use to
get the items in the drop down list. You can cycle through these items and
parse the strings as you see fit.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Dave Bailey said:
I need to read the contents of a dropdown listbox up to a space and then
eliminate everything to the right of the space(including the space). How do
I do this?
 
Hi dave,

String.SubString can do it.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Dave Bailey said:
I need to read the contents of a dropdown listbox up to a space and then
eliminate everything to the right of the space(including the space). How do
I do this?
 
Dave Bailey said:
I need to read the contents of a dropdown listbox up to a space and
then eliminate everything to the right of the space(including the
space). How do I do this?

Use IndexOf to find the first space, and Substring to retrieve a
portion of the string:

int index = original.IndexOf(' ');

string trimmed = (index==-1 ? original : original.Substring(0,index));
 
Thanks for all the help. I am using the following code

private string GetSystemCode(

string code = sysCodeList.SelectedItem.ToString()
int offset = code.IndexOf(' ')

if (systemCodeCheck.Checked == true

return " and wo3 = '" + ((offset == -1)? code: code.Substring(0, offset)) + "'"

els

return null



Thuis code is part of a select statement which is the where clause. It appears that this code does not trim the drop down list box to the information that is on the left side of the first space.

Any suggestions

Thanks

Dave
 
Dave Bailey said:
Thanks for all the help. I am using the following code:

private string GetSystemCode()
{
string code = sysCodeList.SelectedItem.ToString();
int offset = code.IndexOf(' ');

if (systemCodeCheck.Checked == true)
{
return " and wo3 = '" + ((offset == -1)? code: code.Substring(0,
offset)) + "'";
}
else
{
return null;
}
}

Thuis code is part of a select statement which is the where clause.
It appears that this code does not trim the drop down list box to the
information that is on the left side of the first space.

Any suggestions?

Yes - step through it, find out what offset is, find out what code is,
find out what the returned value is, etc.
 
Back
Top