using system;
using system.collections.generic;
using system.linq;
using system.text;
namespace 字串練習2
//倒序輸出字串 如: 「i love you 」輸出為「you love i 」
//string str = "i love you";
以空格分隔取出字串陣列
//string strs = str.split(' ');
遍歷字串陣列
//for (int i = strs.length-1; i >=0; i--)
//取出年 月 日 split使用
//string date = "2023年12月12日";
按照年 月 日進行分隔成陣列
//string dates = date.split(new char );
//foreach (string item in dates)
//",item);
//}//取出年 月 日 substring indexof使用
//string date = "2023年12月12日";
//取出數字年
//string year = date.substring(0, date.indexof("年"));
//取出數字月
//string month = date.substring(date.indexof("年") + 1, date.indexof("月") - date.indexof("年") - 1);
//取出數字日
//string day = date.substring(date.indexof("月") + 1, date.indexof("日") - date.indexof("月") - 1);
//string str = "123-456---789----123-2";
//string strs = str.split(new char , stringsplitoptions.removeemptyentries);
//str = string.join("-",strs);
//讀取文字裡面的資訊,並肩將資訊以一定格式輸出
//讀取路徑下面的文字的所有的行
//string lines = file.readalllines(@"c:\documents and settings\mlq\桌面\1.csv", encoding.default);
遍歷輸出
//foreach (string item in lines)
//, stringsplitoptions.removeemptyentries);
// //按照格式輸出姓名和**
// console.writeline("姓名:,**", (arr[0] + arr[1]), arr[2]);
//
//}123-456---789-----123-2,把類似字串中重複的符號去掉,即得到123-456-789-123-2
//string str = "123-456---789-----123-2";
以-將字串分割成字串陣列
//string strs = str.split(new char,stringsplitoptions.removeemptyentries);
在用-將字串連線起來
//str = string.join("-", strs);
從檔案路徑中提取檔名(包含字尾),比如:從c:/a/b.txt中,提取出b.txt這個檔名出來
//string path = "c:/a/b.txt";
用到indexof和substring
//string name = path.substring(path.lastindexof("/") + 1);
從檔案路徑中提取檔名(不包含字尾),比如:從c:/a/b.txt中,提取出b這個檔名出來
//string path = "c:/a/b.txt";
找到最後乙個/出現的位置和 . 出現的位置,擷取的長度為點出現的位置減去最後乙個/出現的位置再減1
//string name = path.substring(path.lastindexof("/")+1,path.indexof(".")-path.lastindexof("/")-1);
獲取網域名稱如:「[email protected]」
//string mail = "[email protected]";
找到@和.的位置,從@的後一位開始擷取,擷取的長度為.的位置減去@的位置再減1
//string name = mail.substring(mail.indexof("@")+1,mail.indexof(".")-mail.indexof("@")-1);
獲取網域名稱如:「[email protected]」
//string mail = "[email protected]";
擷取字串開始的位置
//int start = mail.indexof('@') + 1;
擷取字串結束的位置
//int end = mail.indexof(".");
擷取字串的長度
//int length = end - start;
擷取字串
//string name = mail.substring(start,length);
輸出擷取的字串
//輸出ip位址,埠號和服務:如192.168.1.123[port=21,type=ftp]或192.168.1.123[port=21]
string str = "192.168.1.123[port=21]";
//string str = "192.168.1.123[port=21,type=ftp]";
//ip
string ip = "";
//port
string port = "";
//type預設為http
//有點協議不存在type,判斷是否存在type,不存在,則預設為http,存在,則輸出存在的資料
if (str.contains("type"))
else
console.writeline("ip:,埠:,服務:",ip,port,type);
console.read();}}
}
字串處理 字串反轉
請原諒博主今天很閒,於是乎博主又開始更新微博了。這次要更新的問題是 編寫乙個函式,反轉乙個單詞的順序。例如 do or do not,there is no try.就要反轉成 try.no is there not,do or do 大家要認真看看這道題,這道題和大家想象的貌似有點不同。首先字串反...
字串處理
uncode與ansi字串轉換 我們使用windows函式multibytetowidechar將多位元組字串轉換成寬字元字串。函式如下 int multibytetowidechar uintcodepage dworddwflags lpcstrlpmultibytestr intcbmulti...
字串處理
byte array new byte 2 array system.text.encoding.default.getbytes 啊 int i1 short array 0 0 int i2 short array 1 0 unicode解碼方式下的漢字碼 array system.text.e...