Click here to Skip to main content
12,076,727 members (48,092 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: MVC string operations
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 4:52am
Edited 19-Oct-12 6:45am
_Zorro_5.5K
v2
Comments
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.
--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
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?
--SA

1 solution

Rate this: bad
 
good
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,
—SA
  Permalink  

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
Web03 | 2.8.160212.1 | Last Updated 19 Oct 2012
Copyright © CodeProject, 1999-2016
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