字符串分割的使用实例代码

string agentinfo = userinfo.attribute19.tostring();
            string[] myagent = agentinfo.split(new string[] { “$#$” }, stringsplitoptions.none);
            if (myagent.length == 3)
            {
                this.qlookupmyagent.text = myagent[0].tostring();
                this.qcalenderstartdate.value = myagent[1].tostring();
                this.qcalenderenddate.value = myagent[2].tostring();
            } 

VS2003下用下面的方法:

1、用字符串分隔

using System.Text.RegularExpressions;

 

string str=”aaajsbbbjsccc”;

string[] sArray=Regex.Split(str,”js”,RegexOptions.IgnoreCase);

foreach (string i in sArray) Response.Write(i.ToString() + “
“);

输出结果:
aaa
bbb
ccc

2、用多个字符来分隔:

string str=”aaajbbbscccjdddseee”;

string[] sArray=str.Split(new char[2]{‘j’,’s’});

foreach(string i in sArray) Response.Write(i.ToString() + “
“); 

输出结果:
aaa
bbb
ccc
ddd
eee

3、用单个字符来分隔:

string str=”aaajbbbjccc”;

string[] sArray=str.Split(‘j’);

foreach(string i in sArray) Response.Write(i.ToString() + “
“);

输出结果:
aaa
bbb
ccc

 

 

  

以上就是字符串分割的使用实例代码的详细内容,更多请关注【创想鸟】其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2440571.html

(0)
上一篇 2025年3月3日 12:29:45
下一篇 2025年2月25日 21:21:02

AD推荐 黄金广告位招租... 更多推荐

相关推荐

发表回复

登录后才能评论