以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]如何查找替换字符 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=187213) |
-- 作者:moseser -- 发布时间:2023/6/30 13:47:00 -- [求助]如何查找替换字符 我想做一个可以增加注释的计算器 用中括号,注释内容 【注释内容】 如一个字符串 dim str as string = "9【长度】*3【宽度】" 如何可以查找 【****】,将其替换成空
|
-- 作者:有点蓝 -- 发布时间:2023/6/30 13:59:00 -- 方法1、http://www.foxtable.com/webhelp/topics/1338.htm Dim str As String = "9【长度】*3【宽度】" Dim idx1 As Integer = str.IndexOf("【") Do While idx1 > -1 Dim idx2 As Integer = str.IndexOf("】", idx1) If idx2 > -1 Then str = str.Substring(0, idx1) & str.Substring( idx2 + 1) End If idx1 = str.IndexOf("【") Loop Output.Show(str) 2、 Dim pattern As String = "【\\w+(?=】)】" Dim txt = "9【长度】*3【宽度】" Dim str = System.Text.RegularExpressions.Regex.Replace(txt , pattern , "") Output.Show(str) |
-- 作者:y2287958 -- 发布时间:2023/6/30 14:14:00 -- Dim str As String = "9【长度】*3【宽度】" Dim lst As New List(Of String) For Each st As String In str.Split ("】") lst.add(st.Split ("【")(0)) Next Output.Show (String.Join ("", lst))
|