以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]统一字符串中的分隔符 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=69623) |
-- 作者:wyz20130512 -- 发布时间:2015/6/8 12:05:00 -- [求助]统一字符串中的分隔符 Dim str As String = "玉米20根 红心苕15 生姜10 蒜米3 薄青椒10 杭椒5 " 如何用代码将上面的字符串中的空格统一为一个空格呢(即分隔符仅为一个空格)?请老师指教!!
|
-- 作者:大红袍 -- 发布时间:2015/6/8 12:36:00 -- Dim str As String = "玉米20根 红心苕15 生姜10 蒜米3 薄青椒10 杭椒5 " Dim reg As new System.Text.RegularExpressions.Regex(" +") str = reg.replace(str, " ") msgbox(str.Trim()) |
-- 作者:wyz20130512 -- 发布时间:2015/6/8 12:41:00 -- 回复:(大红袍)Dim str As String = "玉米20根 ... 达到效果了,可代码看不懂,Foxtable中没看到相关的介绍。 感谢“大红袍”老师!
|
-- 作者:lsy -- 发布时间:2015/6/8 13:02:00 -- Dim str As String = "玉米20根 红心苕15 生姜 10 蒜米3 薄青椒10 杭椒5 " For i As Integer = 9999 To 2 Step - 1 Dim s As New String(" ",i) str = str.Replace(s," ") Next Output.Show(str)
|
-- 作者:wyz20130512 -- 发布时间:2015/6/8 13:25:00 -- 回复:(lsy)Dim str As String = "玉米20根 红... 此方法甚妙,十分感谢“lsy”老师,用Foxtable本身的方法解决了这个问题。 |
-- 作者:大红袍 -- 发布时间:2015/6/8 14:53:00 -- Dim str As String = "玉米20根 红心苕15 生姜 10 蒜米3 薄青椒10 杭椒5 " Dim nstr As String = "" For Each s As String In str.Split(" ") If s.trim > "" Then nstr &= " " & s End If Next Output.Show(nstr) |
-- 作者:wyz20130512 -- 发布时间:2015/6/27 22:38:00 -- 回复:(大红袍)Dim str As String = "玉米20根 ... "大红袍"老师的先分割后合并的方法更妙.十分感谢! 经测试.Trim不用,结果也正确. Dim str As String = "玉米20根 红心苕15 生姜10 蒜米3 薄青椒10 杭椒5 " Dim nstr As String = "" For Each s As String In str.Split(" ") If s > "" Then nstr = nstr & " " & s End If Next |