Hi
I just want to return 'Robertsbr1234' from 'varCellItemName'
varCellItemName = "Robertsbr1234, jim";
int varLocation = varCellItemName.IndexOf(",");
I can find the index of "," which is 13 (zero based).
how to just get 'Robertsbr1234'
Thanks
How to return text from a text string
-
- Posts: 28
- Joined: Wed Aug 12, 2015 6:44 pm
Re: How to return text from a text string
kinda figured it out
string input= varCellItemName;
int stop = input.IndexOf(",");
string output = input.Substring(0, stop);
This displays "Robertsbr1234"
string input= varCellItemName;
int stop = input.IndexOf(",");
string output = input.Substring(0, stop);
This displays "Robertsbr1234"
Re: How to return text from a text string
You can also use the "Split()" function of the string class.
string result = "Robertsbr1234, jim".Split(',')[0];
Split() returns an array of strings, and you want the 1st one (0-based index in .NET).
If you want a specific string out of the array, you would need to loop over the array.
string result = "Robertsbr1234, jim".Split(',')[0];
Split() returns an array of strings, and you want the 1st one (0-based index in .NET).
If you want a specific string out of the array, you would need to loop over the array.
Shortcuts usually aren't...