How to check whether the value contains the special character or not ?
If yes, how to filter that special character from the string?
Can anyone please help
Hi @divyaag you can use regex activities in uipath like ismatch activity with expression, which would return boolean value as whether it has or not
β[1]*$β
And this xaml can help you, it has sample of your issue been resolved @divyaag
regex.xaml (4.9 KB)
You can also remove or replace the special characters in a string buddy with match activity, but with the above expression you can find the value containes special character or not
-
!@#$%^&*(),.?":{}|<> β©οΈ
Is that working buddy.! @divyaag
@Palaniyappan , unfortunately no β¦
Its returning true even if there are no special characters. Can you please help
β[1]+$β
Oh no worries @divyaag use this to check whether it has other characters apart from abcd or 1234
that would give false if it has any special characters or gives us true if the string has any one special characters β¦ @divyaag
This worked kindly refer this xaml
regex.xaml (4.8 KB)
-
A-Za-z0-9 β©οΈ
Thank you @Palaniyappan. yes it worked for me
Can you please help me to remove the special characters from the string?
Sure @divyaag
System.Text.RegularExpressions.Regex.Replace(YOUR VARIABLE HERE, β[1]+$β, ββ)
-
A-Za-z0-9 β©οΈ
Sorry @Palaniyappan, its not working again
@Palaniyappan was almost right
you need System.Text.RegularExpressions.Regex.Replace(youvariable, β[^A-Za-z0-9 ]β, ββ)
And carefull with the quotes, if you just copy-paste from here, it wonβt work, you need to manually replace them.
is that working nowβ¦i checked and sent you a xaml, it worked @divyaag
Best regex pattern you could use in this scenario would be [^\w]
.
[^\w]
Match a single character not present in the list below[^\w]
\w
matches any word character (equal to[a-zA-Z0-9_]
)
Please note _
is not considered as a special character when you use [^\w]
.
If you want to allow a special character, you can add it to the pattern.
So if you want to allow @
just change the pattern to [^\w@]
inputString = "I @am #a $clean{ string ;now."
pattern1 = "[^\w]"
pattern2 = "[^\w .]"
pattern1Output = System.Text.RegularExpressions.Regex.Replace(inputString, pattern1, "")
pattern2Output = System.Text.RegularExpressions.Regex.Replace(inputString, pattern2, "")
In the above example
pattern1 allows only a-z, A-Z, 0-9 and _
pattern2 allows a-z, A-Z, 0-9, _, space and period.Outputs for the above examples would be.
With pattern 1:Iamacleanstringnow
With pattern 2:I am a clean string now.
Sample Visual Basic code: Regular Expression - Remove Special Characters, Visual Basic - rextester
Regular expression is a powerful tool and I would recommend everyone to learn it. I used regex101.com to learn it.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.