新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
全面測試C#字符串
1.C#字符串分割

目前成都創(chuàng)新互聯(lián)已為上1000+的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)絡(luò)空間、網(wǎng)站托管運(yùn)營、企業(yè)網(wǎng)站設(shè)計、瑞金網(wǎng)站維護(hù)等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
- string url = "http://asdfsfd asdf asdfsdf";
- string[] sss = GetString(url," ");
- foreach(string str in sss)
- {
- Response.Write(str.ToString() +" ");
- }
- private string[] GetString(string str,string cutStr)
- {
- char[] cutChar = cutStr.ToCharArray();
- string[] sArray = str.Split(cutChar);
- return sArray;
- }
2.C#字符串截取
- public static string GetFirstString(string stringToSub, int length)
- {
- Regex regex = new Regex("[\u4e00-\u9fa5]+", RegexOptions.Compiled);
- char[] stringChar = stringToSub.ToCharArray();
- StringBuilder sb = new StringBuilder();
- int nLength = 0;
- bool isCut=false;
- for(int i = 0; i < stringChar.Length; i++)
- {
- if (regex.IsMatch((stringChar[i]).ToString()))
- {
- sb.Append(stringChar[i]);
- nLength += 2;
- }
- else
- {
- sb.Append(stringChar[i]);
- nLengthnLength = nLength + 1;
- }
- if (nLength > length)
- {
- isCut=true;
- break;
- }
- }
- if(isCut)
- return sb.ToString()+"...";
- else
- return sb.ToString();
- }
3.取子串函數(shù)SubString
- string tmp2 = tmp1.SubString(0,3);
- 相當(dāng)于vb.net中的mid
- tring str="abcdefg";
- string strstr1=str.Substring(2,3);//str1="cde"
4.C#中有什么函數(shù)可以判斷某一C#字符串中是否存在著某一字符?如:"akkk*kkk"是否有“*”?
- string s = "akkk*kkk";
- int i = s.IndexOf("*");
- if( i != -1) 包含
- else 不包含
5.右對齊此實例中的字符,在左邊用指定的 Unicode 字符填充以達(dá)到指定的總長度。
- public string PadLeft(int, char);
- str = "256";
- strstr = str.PadLeft(5,"0"); //str = "00256"
網(wǎng)站名稱:全面測試C#字符串
分享地址:http://fisionsoft.com.cn/article/cosjpgs.html


咨詢
建站咨詢
