Reputation: 117
I have a ListBox FILLED with IDs + Employees. They're all listed as: ID - Employee Name.
Now, I want to make a Select Query with the Selected ID. But if I do, it will select ID + Employee Name = Crash. How can I "trim" it somehow so I can only get the ID? Thanks.
Upvotes: 0
Views: 31
Reputation: 4168
The Split()
method is likely the best way to achieve what it is you're looking to accomplish.
Say for example you had a String value for your ID - Employee Name
combination as follows:
String listIndexValue = "0AB456MyID01 - John Doe";
You can use the following to retrieve the ID with:
String id = listIndexValue.Split('-')[0].Trim();
This would return: 0AB456MyID01
.
The Split()
method returns an array of String values based on where your original String is split. In this case, there are two values returned, 0AB456MyID01
and John Doe
(whitespaces included). Obviously arrays have indexes, and since we only wish to retrieve one value, we call for 0AB456MyID01
, or index 0. Trim()
obviously will remove the trailing whitespace in 0AB456MyID01
.
Upvotes: 1