iT邦幫忙

0

將字串拆開 C#

  • 分享至 

  • twitterImage

請問要如何將字串拆開阿
譬如 12AB34CD 數字和英文混雜 要把每一個拆開
因為split分割字串 上述字串沒有東西分割 所以我也不知道怎麼處理他

石頭 iT邦高手 1 級 ‧ 2021-03-13 15:47:25 檢舉
KeyWord: Regex + group
skyksl066 iT邦新手 4 級 ‧ 2021-03-14 16:47:24 檢舉
split(‘’)不行嗎?
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
2
海綿寶寶
iT邦大神 1 級 ‧ 2021-03-13 18:56:39
最佳解答
using System.Text.RegularExpressions;

Regex re = new Regex(@"([a-zA-Z]+)(\d+)");
Match result = re.Match(input);

string alphaPart = result.Groups[1].Value;
string numberPart = result.Groups[2].Value;

資料來源

yonghong iT邦新手 5 級 ‧ 2021-03-14 11:03:15 檢舉

感謝大神幫忙

0
Jimmy
iT邦新手 5 級 ‧ 2021-03-14 10:57:20

轉字元字串囉;

0
woodycheung
iT邦見習生 ‧ 2021-03-15 11:29:23
string str = "12AB34CD";
char[] arr = str.ToCharArray();
foreach (char ch in arr)
{
    Console.WriteLine(ch);
}
Console.ReadLine();

我要發表回答

立即登入回答