zoukankan      html  css  js  c++  java
  • 字符串分割的使用

    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() + "<br>");


    输出结果:
    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() + "<br>"); 


    输出结果:
    aaa
    bbb
    ccc
    ddd
    eee

    3、用单个字符来分隔:

    string str="aaajbbbjccc";

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

    foreach(string i in sArray) Response.Write(i.ToString() + "<br>");

    输出结果:
    aaa
    bbb
    ccc

     
     
  • 相关阅读:
    UVA 1386 Cellular Automaton
    ZOJ 3331 Process the Tasks
    CodeForces 650B Image Preview
    CodeForces 650A Watchmen
    CodeForces 651B Beautiful Paintings
    CodeForces 651A Joysticks
    HUST 1601 Shepherd
    HUST 1602 Substring
    HUST 1600 Lucky Numbers
    POJ 3991 Seinfeld
  • 原文地址:https://www.cnblogs.com/klsw/p/6965034.html
Copyright © 2011-2022 走看看