入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

C#里分割字符串的一个方法

创建时间:2014-07-15 投稿人: 浏览次数:2907
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class StringExtention {

    public static string[] SplitWithString(string sourceString, string splitString){
        
        List<string> arrayList = new List<string>();
        string s = string.Empty;
        while (sourceString.IndexOf(splitString) > -1)
        {
            s = sourceString.Substring(0, sourceString.IndexOf(splitString));
            sourceString = sourceString.Substring(sourceString.IndexOf(splitString) + splitString.Length);
            arrayList.Add(s);
        }
        arrayList.Add(sourceString);
        return arrayList.ToArray();
    }
}


例如 字符串 string str = "abc1234efg";

StringExtention.SplitWithString(str,"1234"); 得到的两个字符串为 “abc” , "efg"。

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像