gpt4 book ai didi

vb.net - 如何用单词 "and"替换最后一次出现的 a ?

转载 作者:行者123 更新时间:2023-12-02 00:42:29 24 4
gpt4 key购买 nike

如何用单词 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)

Sample Image

最佳答案

在这里,我什至没有看到你的代码,但我通过查看图片得到了你想要做的事情。它可以在较短的版本中完成,但我已经解释了每一行中发生的事情,所以它很长。

我写了这段代码:

 '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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com