Click here to Skip to main content
13,005,198 members (60,977 online)
Rate this:
Please Sign up or sign in to vote.
Hi all,

I want to split a string in mvc,
for example
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 19-Oct-12 3:52am
Updated 19-Oct-12 5:45am
Wes Aday 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.
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!".
Sergey Alexandrovich Kryukov 19-Oct-12 12:47pm
Split in MVC? If it wasn't MVC, will the code be different? Ever heard about separation of concerns?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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

Good luck,

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170627.1 | Last Updated 19 Oct 2012
Copyright © CodeProject, 1999-2017
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