在MVC中分割字串 [英] Split a string in mvc

查看:110
本文介绍了在MVC中分割字串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想在mvc中分割字符串,
例如

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"
                }
}



我想将Rk保存在一个变量中,将Prabakar保存在另一个变量中.

我不知道如何阅读内容.符号.
我用split()分割了字符串.
但是我无法按预期阅读内容.

请帮我尽快.
在此先感谢.



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.

推荐答案

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



祝你好运,

—SA



Good luck,

—SA


这篇关于在MVC中分割字串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆