如何使用c#asp.net在字符串中使用分段 [英] how to use segmentation in a string using c# asp.net

查看:62
本文介绍了如何使用c#asp.net在字符串中使用分段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,请您解释一下c#asp.net中的字符串代码

Hello guys can you please explain the code for segment a string in c# asp.net

推荐答案

我不确定你的意思:段a字符串可能意味着几件事。

所以首先看一下 string.Split [ ^ ],将逗号分隔数据等内容转换为单独的条目:

I'm not sure what you mean exactly: "segment a string" could mean several things.
So start by looking at string.Split[^], which converts things like comma delimited data into separate entries:
string inp = "Mike,Joe,Steve,James";
string[] names = inp.Split(',');



然后查看 string.Substring [ ^ ]允许您从字符串中填写特定大小的块:


And then look at string.Substring[^] which allows you to spilt out specific sized "chunks" from a string:

string inp = "Mike Joe  SteveJames";
int count = inp.Length / 5;
string[] names = new string[count];
for (int i = 0; i < count; i++)
    {
    names[i] = inp.Substring(i * 5, 5);
    }


这篇关于如何使用c#asp.net在字符串中使用分段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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