作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何用单词 and 替换最后一次出现的 a ?你能给我一个主意吗?
我有 3 个复选框,1 个富文本框 显示输出,1个按钮
(Aparri)或(Camalanuigan)或(Lallo)
Cagayan(Aparri, Camalanuigan) 或 Cagayan(Aparri,Camalanuigan,Lallo)
我希望输出是这样的:#Cagayan(Aparri and Camalanuigan) 或 #Cagayan(Aparri,Camalanuigan And Lallo)
这是我的代码:
Dim rws As String
If Aparri.Checked = True Then
close_parenthesis.Checked = True
If rws = "" Then
rws = "(" + Aparri.Text
End If
End If
If Aparri.Checked = False Then
rws = ""
End If
If Camalanuigan.Checked = True Then
close_parenthesis.Checked = True
If rws = "" Then
rws = "(" + Camalanuigan.Text
Else
rws = rws & ", " & Camalanuigan.Text
End If
End If
If Lallo.Checked = True Then
close_parenthesis.Checked = True
If rws = "" Then
rws = "(" + Lallo.Text
Else
rws = rws & ", " & Lallo.Text
End If
End If
If close_parenthesis.Checked = True Then
If rws = "" Then
Else
rws = rws + close_parenthesis.Text
End If
End If
Display.Text = rws.ToString
输出:(Aparri,Camalanuigan,Lallo)
我想要这样的出局(Aparri、Camalanuigan 和 Lallo)
最佳答案
在这里,我什至没有看到你的代码,但我通过查看图片得到了你想要做的事情。它可以在较短的版本中完成,但我已经解释了每一行中发生的事情,所以它很长。
我写了这段代码:
'let's say the string is "Aparri, Camalanuigan, Lallo" . that's what your code does, right?
dim Strng as string = "Aparri, Camalanuigan, Lallo"
'now find the position of last appearing ","
Dim comaposition As Integer
comaposition = Strng.LastIndexOf(",") 'it is zero based
'if not found, it will return -1 and u can exit, no need to do the work
if commaposition = "-1" then
exit sub
end if
'remove the comma
Dim String_After_Removing_Comma As String
String_After_Removing_Comma = Strng.Remove(comaposition, 1)
'add "and" in the same position where comma was found
Dim final_string As String
final_string = String_After_Removing_Comma.Insert(comaposition, " and")
'show it on the textbox
DisplayTxt.Text = final_string
您可以在找到最终字符串(代码中的 rws)后执行此操作。希望这有帮助
关于vb.net - 如何用单词 "and"替换最后一次出现的 a ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45831829/
我是一名优秀的程序员,十分优秀!