以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]字符串数组  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=124288)

--  作者:天一生水
--  发布时间:2018/9/3 22:24:00
--  [求助]字符串数组
想替换字符串中的句号,末尾的句号除外,请蓝老师帮忙改一下,谢谢!
代码结果为"你好,你好,你好。"

\'\'\'
Dim str As String = "你好,你好。你好。"
.......

Dim lst As new List(Of String)
If lst.Count >= 1 Then
    For i As Count = 0 To lst.Count-1
        If i <> lst.Count -1 Then
            lst(i).Replace("。",",")
        End If
    Next
End If
Output.Show(lst)


--  作者:有点蓝
--  发布时间:2018/9/3 22:29:00
--  
lst(i) = lst(i).TrimEnd("。").Replace("。",",") & "。"
--  作者:天一生水
--  发布时间:2018/9/4 11:56:00
--  

1、这样没问题:

\'\'\'
Dim str As String = "在控件中每输入,或删除一个字符。都会触发TextChanged事件,"
str = str.TrimEnd("。").TrimEnd(",").TrimEnd(";").Replace(":","").Replace(";",",").Replace(",",",").Replace("、",",").Replace("。",",") & "。"
Output.Show(str)

 

2、文本框textchang代码,在文本框中编辑时为什么出现一些句号单独成了一段,也删不掉:

Dim txt As WinForm.TextBox = e.Form.Controls("TextBox01")
If txt.text.EndsWith(chr(10)) = False Then
    Dim ary() As String = txt.Text.Split(chr(13))
    Dim str As String = ""
    For Each s As String In ary

        s =s.TrimEnd("。").TrimEnd(",").TrimEnd(";").Replace(":","").Replace(";",",").Replace(",",",").Replace("、",",").Replace("。",",") & "。"
        If s <> chr(10) Then
            str &= "    " & s.trim & vbcrlf \'行首空格
            str &= vbcrlf & ""
        End If
    Next
    systemready = False
    txt.text = str
    systemready = True
End If




--  作者:有点甜
--  发布时间:2018/9/4 12:22:00
--  
\'\'\'
Dim txt As WinForm.TextBox = e.Form.Controls("TextBox2")
Dim ary() As String = txt.Text.replace(chr(10), "").Split(chr(13))
Dim str As String = ""
For Each s As String In ary
    If s.trim > "" Then
        s =s.TrimEnd("。").TrimEnd(",").TrimEnd(";").Replace(":","").Replace(";",",").Replace(",",",").Replace("、",",").Replace("。",",") & "。"
    End If
   
    str &= "    " & s.trim & vbcrlf \'行首空格
Next
systemready = False
txt.text = str
systemready = True