本文介绍了你如何用单词“and"替换最后一次出现的 a ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用单词 and 替换最后一次出现的 a ?你能给我一个想法吗?

How do you replace the last occurance of a , with the word and? Can you please give me an idea?

我有 3 个复选框,1 个富文本框显示输出,1个按钮

i have 3 checkboxes, 1 rich textbox to display the output, 1 button

(Aparri) 或 (Camalanuigan) 或 (Lallo)

(Aparri) or (Camalanuigan) or (Lallo)

卡加延(阿帕里、卡马兰努伊根)或卡加延(阿帕里、卡马兰努伊根、拉洛)

Cagayan(Aparri, Camalanuigan) or Cagayan(Aparri,Camalanuigan,Lallo)

我希望输出是这样的:#Cagayan(Aparri and Camalanuigan) 或 #Cagayan(Aparri,Camalanuigan And Lallo)

I would like the output to be like this: #Cagayan(Aparri and Camalanuigan) or #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)

Output: (Aparri,Camalanuigan,Lallo)

我想要这样的出局(Aparri、Camalanuigan 和 Lallo)

i want the out like this (Aparri,Camalanuigan and Lallo)

推荐答案

在这里,我什至没有看到你的代码,但我通过查看图片知道你想要做什么.它可以用更短的版本完成,但我已经解释了每一行的内容,所以很长.

Here, I haven't even seen your code but I get what you want to do by looking at the picture. It can be done in shorter version but I have explained what's going on in each and every line so it's lengthy.

我写了这段代码:

 '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)后执行此操作.希望这有帮助

You can do this thing after finding your final string (rws in your code).Hope this helps

这篇关于你如何用单词“and"替换最后一次出现的 a ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 13:42