|
-
Apr 15th, 2007, 03:44 AM
#1
Thread Starter
Lively Member
[RESOLVED] space as delimeter for string split
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);
-
Apr 15th, 2007, 03:57 AM
#2
Re: space as delimeter for string split
A space does not constitute a regular expression. Just use normal String.Split.
Code:
string s = "sss ttt";
string words = s.Split(' ');
-
Apr 15th, 2007, 04:06 AM
#3
Thread Starter
Lively Member
Re: space as delimeter for string split
Well i tried it but i get an error as follows
Error 1 Cannot implicitly convert type 'string[]' to 'string'
-
Apr 15th, 2007, 04:09 AM
#4
Re: space as delimeter for string split
I knew I would do that it's meant to be string[] words.
-
Apr 15th, 2007, 04:25 AM
#5
Thread Starter
Lively Member
Re: space as delimeter for string split
ya thanks alot ....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.
-
Apr 15th, 2007, 04:39 AM
#6
Re: space as delimeter for string split
Use Substring:
Code:
string whole_thing = "abcdefgh";
string just_a_bit = whole_thing.Substring(whole_thing.Length - 3, 3);
-
Apr 15th, 2007, 06:21 AM
#7
Thread Starter
Lively Member
Re: space as delimeter for string split
Hi,
Thanks so much. It worked fine.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|