Click here to Skip to main content
Rate this: bad
good
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.4K
v2
Comments
Wes Aday at 19-Oct-12 9:57am
   
Okay so split it again using |
Karthik. A at 19-Oct-12 10:30am
   
Should be an answer! It IS indeed as simple as that!! +5!
Sergey Alexandrovich Kryukov at 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ő at 19-Oct-12 12:16pm
   
Question is nothing to do with mvc. It is pure string operation.
Sergey Alexandrovich Kryukov at 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 at 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
0 Sergey Alexandrovich Kryukov 335
1 OriginalGriff 250
2 Kornfeld Eliyahu Peter 130
3 DamithSL 120
4 Peter Leow 95
0 OriginalGriff 7,355
1 DamithSL 5,199
2 Sergey Alexandrovich Kryukov 4,942
3 Maciej Los 4,906
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 19 Oct 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