Click here to Skip to main content
16,023,339 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello ,

I have a label whose text is like
abcd , cdef , efg , ijk , lmn

here i need to get the string like cdef,efg,ijk,lmn
i want to remove the abcd

Any Body can you please share any idea to me.

What I have tried:

I tried the below code
C#
string number = file.Split(',')[0].Trim();

it's not working.
Posted
Updated 22-Mar-16 0:28am
v2

As well as the IndexOf solution, if you want to stick with the split function then you'd do it like this

C#
string text = "abcd , cdef , efg , ijk , lmn";
            
// get an array
string[] values = text.Split(new char[]{',', ' '}, StringSplitOptions.RemoveEmptyEntries);
            
if (values.Length > 1)
{
    // if there is more than one item then take everything but the first item
    values = values.Skip(1).ToArray();
}

// convert back to string
text = string.Join(",", values);
 
Share this answer
 
Comments
Karthik_Mahalingam 22-Mar-16 7:39am    
+5, for validation and comments
Try:
C#
string s = "abcd , cdef , efg , ijk , lmn";
s = s.Substring(s.IndexOf(',') + 1).Trim();
 
Share this answer
 

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