String manipulation and comparison

I have two strings “Alpha Beta Architects” and “Alpha Bate Architects, ham house, Cork, Ireland”

The scenario is I want to be able to remove the value “Alpha Beta Architects” from the second string the issue is the spelling mistake located in the second string. Is there a way to over come things such as incorrect spelling with trying to remove or replace?

@duaine.b

system.text.regularexpressions.regex.replace(string,“(Alpha Bate Architects)”,“”)

string is your text input

cheers

@duaine.b

try the below

assign

outputstr=system.text.regularexpressions.regex.replace(secondstring,“(Alpha Bate Architects)”,“Alpha Beta Architects”)

or you want to remove the spelling mistake entirely use this

system.text.regularexpressions.regex.replace(inputstr,“(Alpha Bate Architects)”,“")

cheers

Hi @duaine.b

- Assign -> InputStr = "Alpha Bate Architects, ham house, Cork, Ireland"
- Assign -> Output = System.Text.RegularExpressions.Regex.Match(yourstringinput.ToString,“((?<=\,\s+).*)”).value

Hope it helps!!

@duaine.b - This is a good use-case of ChatGPT activities in UiPath.

Use the OpenAI Activity by adding the package:
image

image

This is the prompt:

"I have a list of items: """ + strList + """

Remove " + strWordToBeRemoved + " from the list and show me the new list. I may have typos in the item name I want to replace. Reply only with the updated list. Do not change the capitalization and order of the words in the list."

Run a couple of tests and modify the prompt if necessary.

I’d like to remove the similar texts and only be left with “ham house, Cork, Ireland”

@duaine.b

use this

system.text.regularexpressions.regex.replace(inputstr,“(Alpha Bate Architects,)”,“")

image

cheers

Hi could you please explain this code

1 Like

[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

from regex101.com we can get explained Regex Pattern

when the input string is “Alpha Beta Architects” it doesn’t remove “Alpha Bate Architects” from “Alpha Bate Architects, ham house, Cork, Ireland”

@duaine.b

yes when there is a “Alpha Bate Architects,” it will remove it

if you want any other let me know

cheers

That was the regular expression, this expression will look the text after first comma (,) and it will store that text. @duaine.b

Apologies think there was some confusion, the string needs to be “Alpha Beta Architects” and it’s trying to find a similar text "Alpha Bate Architects” and remove it from "Alpha Bate Architects, ham house, Cork, Ireland”

@duaine.b

can you send me the input and the expected output

cheers

if the input string is InputStr = “Alpha Bate Architects, ham house, Cork, Ireland” how does it compare “Alpha Beta Architects” and remove this from the input string with the spelling mistake?

String 1 = “Alpha Bate Architects, ham house, Cork, Ireland”
String 2 = “Alpha Beta Architects”
Expected results = "ham house, Cork, Ireland”

The difference between string one and two is that there’s a spelling mistake bate not beta

@duaine.b - Check my answer above. This is a situation where “similar words” are being replaced and cannot be done with just RegEx. String manipulation and comparison - #5 by argin.lerit

cheers

@duaine.b

outputstr=If(string2.Split(“,“c)(0).Replace(” “,””).ToLower.trim.Equals(string1.ToLower.Trim),string2,String.Join(“,”,string2.Split(","c).Skip(1).ToArray))

use it in assign activity outputstr is the value

if true gives the same value ,else gives you the output as you expecting