Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hello ,
 
I have a label whose text is like
 abcd , cdef , efg , ijk , lmn <pre>
 
i need to get the part before the first occurrence of ' , ' ie abcd. 
 
 i thought of using string.split() or string.substring() but it's not generic as i need to have the position of the characters which i don't have. i need something generic.
Posted 3-Sep-12 2:40am
Edited 3-Sep-12 2:41am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

try this:
string part=Mystring.SubString(0,Mystring.IndexOf(','));
  Permalink  
v2
Comments
Kuthuparakkal at 3-Sep-12 8:19am
   
5+
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

This should work:
 
 string s = "abcd, cdef, efg, ijk, lmn";
 
 string result = s.Substring(0, s.IndexOf(","));
  Permalink  
Comments
Prasad_Kulkarni at 3-Sep-12 8:22am
   
Good one +5
Rahul Rajat Singh at 3-Sep-12 8:23am
   
Thanks.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This should work:
 
string input = "abcd , cdef , efg , ijk , lmn";
 
string[] splitString = input.split(',');
 
string result = splitString[0].Trim();
  Permalink  
Comments
__TR__ at 3-Sep-12 7:48am
   
5+
Manas Bhardwaj at 3-Sep-12 7:49am
   
thx!
Prasad_Kulkarni at 3-Sep-12 8:21am
   
My 5!
Manas Bhardwaj at 3-Sep-12 8:41am
   
thx!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hello
 
Please check below code it will use for getting string as per your need
 
  string ReplaceText = @" abcd , cdef , efg , ijk , lmn";
  ReplaceText = ReplaceText.Substring(0, ReplaceText.IndexOf(","));
  Permalink  
Comments
Kuthuparakkal at 3-Sep-12 8:19am
   
inefficient

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



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 3 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100