How to get the text after last semi colon ( ; ) ?
Note : The count of the semi colon ( ; ) will change for each text. but we need to identify the last semi colon ( ; ) and get the text next to it
Sample texts :
1 . Passenger car ; Mercedes-Benz ; C-Class
Passenger car ; VW ; EOS, GOLF, PASSAT; PASSAT CC, POLO; SHARAN
if you see there are 2 semicolons in this first text & 3 semicolons in this seond text
mkankatala
(Mahesh Kankatala)
August 9, 2023, 12:34pm
2
Hi @Sathish_Kumar_S
=> Assign -> StrVar = "Passenger car ; Mercedes-Benz ; C-Class"
=> Assign -> Output = StrVar.Split(";").Last.Trim
It will give the value after the last semi column.
Check the below image for better understanding.
Hope it helps!!
rlgandu
(Rlgandu)
August 9, 2023, 12:37pm
3
@Sathish_Kumar_S
Assign activity:
LastSemicolonIndex = InputText.LastIndexOf(“;”)
Assign activity:
LastText = InputText.Substring(LastSemicolonIndex + 1).Trim()
Akshay_B
(Akshay B)
August 9, 2023, 12:39pm
4
Hello @Sathish_Kumar_S ,
You can use the Following expression:
String_Variable=Input_Var.Split(";"c).Last
Hope this Helps
Regards;)
Hi @Sathish_Kumar_S
Try once with the regex !
1.StringVariable = System.Text.RegularExpressions.Regex.Split(" Passenger car ; Mercedes-Benz ; C-Class",“;”).Last
StringVariable=System.Text.RegularExpressions.Regex.Split(“Passenger car ; VW ; EOS, GOLF, PASSAT; PASSAT CC, POLO; SHARAN”,“;”).Last
For the reference you can see the below screen shot.
Akshay_B:
(";"c).Last
unfortunately, the text next to last semicolon is not working for majority for click text activities.
We need to get all the text next to first semicolon
For Example : 1 : Passenger car ; VW ; Touran, T-Roc
We need only VW ; Touran, T-Roc from about input text
Hello @Sathish_Kumar_S , try this:
Dim inputText As String = “Passenger car ; VW ; EOS, GOLF, PASSAT; PASSAT CC, POLO; SHARAN”
Dim splitText As String() = inputText.Split({";"c}, StringSplitOptions.RemoveEmptyEntries)
Dim lastText As String = splitText.LastOrDefault()
If Not String.IsNullOrEmpty(lastText) Then
’ Process the last text here
MessageBox.Show(lastText)
Else
’ No last text found
End If
Cheers
Hi @Sathish_Kumar_S
if the ‘Passenger car ;’ is constant then you can use this regex pattern
stringvaraible = System.Text.RegularExpressions.Regex.Match(“Passenger car ; VW ; Touran, T-Roc”,“(?<=Passenger car ;\s).*”).Value
lrtetala
(Lakshman Reddy)
August 9, 2023, 2:54pm
10
Hi @Sathish_Kumar_S
Please try this
Input.Split(";".ToCharArray,2).Last
I hope it helps!!
hey!Try this
inputText.Split(“;”.ToCharArray,2).Last
Hope it works
2 Likes
lrtetala
(Lakshman Reddy)
August 10, 2023, 5:56am
12
Hi @Sathish_Kumar_S
Have you tried this?
I hope you got the solution. If yes please mark it as solution to close the loop.