I'm trying to split a string based on a space.
How do I specify a space as the delimeter.
My sample code :
Code:string s = "sss ttt";
string delimeter =@" ";
System.Text.RegularExpressions.Regex.Split(s, delimeter);
Printable View
I'm trying to split a string based on a space.
How do I specify a space as the delimeter.
My sample code :
Code:string s = "sss ttt";
string delimeter =@" ";
System.Text.RegularExpressions.Regex.Split(s, delimeter);
A space does not constitute a regular expression. Just use normal String.Split.
Code:string s = "sss ttt";
string words = s.Split(' ');
Well i tried it but i get an error as follows:o
Error 1 Cannot implicitly convert type 'string[]' to 'string'
I knew I would do that :( it's meant to be string[] words.
ya thanks alot:wave: ....one more problem.
I want to get a part of a string from the right-side of it.
Say for example string "abcdefgh".
I want to be able to return the last 3 characters fgh.
Use Substring:
Code:string whole_thing = "abcdefgh";
string just_a_bit = whole_thing.Substring(whole_thing.Length - 3, 3);
Hi,
Thanks so much. It worked fine.:)