以文本方式查看主题 - Foxtable(狐表) (http://www.foxtable.com/bbs/index.asp) -- 专家坐堂 (http://www.foxtable.com/bbs/list.asp?boardid=2) ---- 如何取字符串中第一个汉字出现的位置 (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=115596) |
-- 作者:煜杭 -- 发布时间:2018/3/9 18:38:00 -- 如何取字符串中第一个汉字出现的位置 Dim str1 As String = "abcdef" 没有汉字 取全部,abcdef Dim str2 As String = "aabbcc中华人民共和国" “中”为第一个汉字,取前面的aabbcc Dim str3 As String = "ab狐/表cd很好" ”狐“为第一个汉字,取ab
|
-- 作者:有点甜 -- 发布时间:2018/3/9 18:56:00 -- Dim str As String = "aabbcc中华人999民共和国" Dim mc = System.Text.RegularExpressions.Regex.Matches(str, ".+?(?=[\\u4e00-\\u9fa5]+)") msgbox(mc(0).value) |
-- 作者:煜杭 -- 发布时间:2018/3/9 19:11:00 -- 谢谢,有汉字的时候能取出,没有汉字的时候出错,老师,没有汉字怎么判断 |
-- 作者:煜杭 -- 发布时间:2018/3/9 19:12:00 -- 有汉字就取汉字之前的内容,没有汉字就取全部 |
-- 作者:有点蓝 -- 发布时间:2018/3/9 20:16:00 -- Dim str As String = "aabbc" Dim mc = System.Text.RegularExpressions.Regex.Matches(str, ".+?(?=[\\u4e00-\\u9fa5]+)") If mc.count = 0 Then msgbox(str) Else msgbox(mc(0).value) End If
|
-- 作者:煜杭 -- 发布时间:2018/3/9 20:19:00 -- 感谢老师 mc原来是个集合 |