+ 2
how to get first word of string in c#
7 odpowiedzi
+ 4
string s = 'Solo learn';
Substring(0,s.IndexOf(' '))
If the words are separated by spaces.
+ 1
String[0].
Example:
string s = "SoloLearn";
s[0] gets 'S'.
+ 1
word not character
+ 1
Trim the sentence to eliminate whitespaces by using string::Trim method.
Split the sentence into string array by using string::Trim method.
Print the first element of the array. Use the subscript operator to refer the element by index. Remember that first element has index of zero.
P.S. Tag C# rather than 'SoloLearn'.
+ 1
Use String.Split() can split the string.
Example:
string s = "Solo Learn";
string[] arr = s.Split();
arr[0] is "Solo".
+ 1
thank you very much
0
regex probably work..probably there are other better method though