How to check the String Contains Consecutive OR OR and Replace them with single OR

Hi All,

How to check the String Contains Consecutive OR OR and Replace them with single OR.

Input string = Design OR OR Drawing OR Painting
Output string = Design OR Drawing OR Painting

Note : this number of OR is not fixed it can be more than two also like OR OR OR OR, we have to replace with single OR.
Please help

Regards
Ritesh

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Replace(yourString,"(\bOR )+","OR ")

Regards,

1 Like

Hi @Yoichi ,

You are really awsome.

Thanks a lots.

Regards,
Ritesh

1 Like

Hi @Yoichi ,
ile:
Facing an issue actually in my Real input data input string is like this
Input string = Design OR OR Drawing OR Painting

Note : in between Two OR there is spaces because of which the above code is failing to make it as a single OR.

Could you please help?

Regards,
Ritesh

Hi,

How about the following expression?

System.Text.RegularExpressions.Regex.Replace(yourString,"(\bOR +)+","OR ")

or

System.Text.RegularExpressions.Regex.Replace(yourString,"(\bOR\s+)+","OR ")

Regards,

1 Like

Cool , its working,

1 Like

Hi @Yoichi ,

Could you please help me one more issue there?

if I get the value as single digit as string i need to make it as 0 in the begining example : input = 3
output 03

Regards,
Ritesh

HI,

Hope the following helps you.

image

CInt(yourString).ToString("00")

or if there might be extra whitespaces, Trim method helps you.

CInt(yourString.Trim).ToString("00")

Regards,

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.