Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have string like " d,j,k,l,k,"

I want to split it till before the first comma.

output is: "d"
Posted

First of all, you cannot parse string.
And second of all, your problem is regarding splitting the string.
See the MSDN documenatation[^].
Some of examples are given over here[^].

And solution towards your problem is,
C#
string str = "d,j,k,l,k,";
string newStr = str.Split(',')[0].ToString();

-KR
 
Share this answer
 
HTML
string s = " d,j,k,l,k,";
string[] words = s.Split(',');
Console.WriteLine(words[0]);

Regards,
Praveen Nelge
 
Share this answer
 
v4
Comments
Krunal Rohit 18-Feb-14 4:47am    
It would print all the comma separated values regardless of comma.
-KR
sachi Dash 18-Feb-14 4:50am    
you didn't get my question. I mean if i want only "hello" from this string what code i should write. I want to split first portion from the string not other portion.
[no name] 18-Feb-14 4:58am    
Done ! check it
@Rahul, thx :)
C#
string[] str = ("d,j,k,l,k").split(',');
now str[0] is your answer....
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900