Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
Hi all,

I want to split a string in mvc,
for example
C#
string strHeader = "Rk | Prabakar ; Mani | Kandan ; Suraj | Kumar;"
string[] strTemp = strHeader .Split(';');

foreach(var a in strTemp)
{
 for (int i = 0; i < count; i++)
                {
                    strZapper =  // Need to read left string eg: "Rk "
                    strMapper =  // Need to read right string eg: " Prabakar"
                }
}


I want to save Rk in one variable and Prabakar in another variable.

I dono how to read the content after | symbol.
I used split() to split the string.
But i could not read the content as expected.

Please help me ASAP.
Thanks in advance.
Posted
Updated 19-Oct-12 5:45am
v2
Comments
[no name] 19-Oct-12 9:57am    
Okay so split it again using |
Karthik. A 19-Oct-12 10:30am    
Should be an answer! It IS indeed as simple as that!! +5!
Sergey Alexandrovich Kryukov 19-Oct-12 12:49pm    
No, it would not be a good answer. For right solution, please see my Solution 1.
--SA
Zoltán Zörgő 19-Oct-12 12:16pm    
Question is nothing to do with mvc. It is pure string operation.
Sergey Alexandrovich Kryukov 19-Oct-12 12:51pm    
Even though I'm answered; when I see such question, I'm tempted to shout: "Next!".
--SA

1 solution

Modify it like this:
C#
string[] strTemp = strHeader .Split(new char[]{ ';', '|', }, System.StringSplitOptions.RemoveEmptyEntries);


Good luck,
—SA
 
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