# 如何分割字符串[英] How to Split the string

### 问题描述

` 地址[0] = " 12345678901234567890201234567890123456789040123456789012345678906012345678901234567890801234567890123456789020123456789012345678904012345678901234567890601234567890123456789080";string 地址 = string.Empty;int ee = 地址[0].Length/2;if (Address[0].Length > 40)地址 = 地址[0].Substring(0, Address[0].Length/2) + "\n" + 地址[0].Substring(Address[0].长度/2, 地址[0].Length/2);`

## 推荐答案

[EDIT]

`string 地址 = string.Empty;int stInd = 0, cnt = Address[0].Length/40;if (Address[0].Length > 40){for (int i = 0; i<= cnt; i++){stInd = i * 40;if (i == cnt)地址 += 地址[0].Substring(stInd);其他地址 += 地址[0].Substring(stInd, 40) + "<br/>";}}其他地址 = 地址[0];`

[编辑]

`public string stringBreak(字符串 objstring, int intLength){string strChr = objstring;string objFinalString = "";if (strChr.Length > intLength){char[] sep = { ' '};字符串[] strChrArray = strChr.Split(sep);int objcount1 = 0;while (objcount1 < strChrArray.Length){if (strChrArray[objcount1].Length > intLength){int i = 0;string obj = "";int objcount = 0;objcount = 0;while (objcount < strChrArray[objcount1].Length){if (objcount > strChrArray[objcount1].Length){obj = strChrArray[objcount1].Substring(objcount - intLength);}其他{试试{obj = strChrArray[objcount1].Substring(objcount, intLength);}catch(例外){obj = strChrArray[objcount1].Substring(objcount);}}objFinalString = objFinalString + "" + obj + " <br> ";objcount = objcount + intLength;}}其他{objFinalString = objFinalString + " " + strChrArray[objcount1];}objcount1 = objcount1 + 1;}strChr = objFinalString;}return strChr;}`

`public static class 扩展方法{public static IEnumerable<string>拆分(this string str, int chunkSize){return Enumerable.Range(0, str.Length/chunkSize).Select(i => str.Substring(i * chunkSize, chunkSize));}}</字符串>`

`string addressString = "12345678901234567890201234567890123456789040123456789012345678906012345678901234567890801234567890123456789020123456789012345678904012345678901234567890601234567890123456789080" ;var 地址 = addressString.Split(40);foreach(字符串地址in地址){//地址部分的事情}`