回答
String userName = "LICTowner";
String prefix = userName.Substring(0,4); // LICT
String restOfWord = userName.Substring(4); // owner
如果前綴總是4個字母則可以使用Substring
方法
在asp.net:
var prefix = username.Substring(0, 4);
其中第一int是起始索引和第二int是長度。
hmmmm ....任何事情之前,A)你應該尋找類似的問題和b)那不是一個很難的問題做......我的意思是,你甚至嘗試? ??
如果前綴始終是4個字母,然後只需使用.Substring方法......作爲
string username;
string prefix=username.Substring(0,4)// or something like that, cant remember off the top of my head
我想我會讓任何人對我的言論感到苦惱,但他們是真的,我的意思是,只要按「」。在用戶名將intellisense顯示您的方法列表後,我確信「substring」會響起一個鐘...... – 2010-05-24 05:46:13
+1同意,這是一個很簡單的事情,它已經覆蓋之前在SO以及所有的網絡。讓我們讓這個網站上的問題比c#101的第一天更有挑戰性吧。 – 2010-05-24 08:08:02
string s = "LICTowner";
Label1.Text= Regex.Replace(s, "[^A-Z]", "");
簡單的正則表達式來刪除比大寫之外的所有字符
如果前綴總是4個字符使用簡單的子字符串
其他 a)刪除所有非大寫字符
string s = "LICTowner";
Label1.Text= Regex.Replace(s, "[^A-Z]", "");
b)在第一個非大寫字符
Label1.Text= Regex.Split(s, "[^A-Z]")[0];
您可以使用子串()函數來獲得前四個字符 分裂。
string mystring = "LISTowner";
string prefixword = mystring.Substring(0,4);
Label label1 = new Label();
label1.Text = prefixword;
string name="aryan";
string prefixwords= name.substring(a,b);
//a from where you want the string
// b till where you need the string now take any label and print the value
string prefixwords= name.substring(0,2);
label lblmsg= new label();
lblmsg=prefixwords.tostring(); // ary
string restofwords= name.substring(2); // an
不錯的代碼...感謝你,先生... – 2012-08-29 11:24:00
- 1. 如何在Python中獲取單詞的前三個字母?
- 2. 如何在Python中將單詞拆分爲單個字母2.7
- 3. 如何將字符串拆分爲單詞並獲取c#中不同的單詞?
- 4. 獲取單詞中的字母數
- 5. 如何拆分C#中指定字符串的單詞?
- 6. 拆分python中的合併單詞
- 7. 如何從一個拆分字符串中提取單詞
- 8. 分割的正則表達式 - 將單詞拆分爲詞素或詞綴
- 9. 如何使用C#中的拆分方法從括號內拆分單詞?
- 10. 如何從Objective-C的NSString中獲取前N個單詞?
- 11. C++獲取目錄前綴
- 12. 如何獲取以大寫字母開頭的所有單詞?
- 13. 如何拆分字符串並獲取最後一部分?
- 14. 拆分太長的單詞與' - '字符
- 15. 拆分並獲得c中字符串的最後部分#
- 16. 如何獲取字符串的單詞?
- 17. 如何自動大寫C#中每個單詞的首字母?
- 18. C# - 如何計算.RTF/.TXT文件中的單詞和字母?
- 19. 獲得的首字母從的前兩個單詞串
- 20. 帶字母的前綴字段
- 21. 獲取句子中每個單詞的第一個字母?
- 22. 如果使用條件前綴[+和後綴+]獲取字符串的一部分
- 23. 如何獲取JQuery中字符串的前三個字母?
- 24. 如何將數字拆分爲組詞?
- 25. 在C++中查找單詞是否爲前綴的函數
- 26. 如何獲取輸入文件並計算每個單詞中的字母並將其打印出來
- 27. SQL Server:如何獲取單詞中的第一個或第二個字母?
- 28. 如何在PHP中匹配具有通用前綴的單詞?
- 29. 從matlab中的字符串中提取前4個字母
- 30. 如何拆分字符串而不丟失任何單詞?
是前綴始終爲4頁的信嗎? – 2010-05-24 05:39:16