How to check titles existing in first name variable

Sample Titles arrTitle={“MR”,“MRS”,“MISS”,“MS”}

  1. Need to check whether given First_Name variable contains Titles or not
  2. If titles not present, then need to add Default title as MR to that first name Variable.

Sample first names
1.WINIFREDMISS
2.REBECCAMS
3.MICHALMR
4.ANDREW
5.JANE
6.HANNAHJAYNE

Thanks in advance

HI @srujana13a5

You can try with this expression

ArrString.Any(function(x) System.Text.RegularExpressions.Regex.Match(InputStr,"^MR|^MRS|^MISS|^MS").ToString.Contains(x))

Check out the XAML file

ArrayStringContainsString.xaml (7.3 KB)

image

Regards
Gokul

Hi,

Hope the following sample helps you.

System.Text.RegularExpressions.Regex.IsMatch(item,"("+String.Join("|",arrTitle)+")$")

Sample20221107-4.zip (2.8 KB)

Regards,

HI @srujana13a5

Check this expression if you have the names in datatable

arrStr={“MR”,“MRS”,“MISS”,“MS”}

(From a In DT.AsEnumerable
Let b= If(System.Text.RegularExpressions.Regex.isMatch(a(0).ToString,String.Join("$|",Arr_Str)),a(0).ToString,a(0).ToString+"MR")
Select Dt1.Rows.Add(b)).CopyToDataTable

If you need for only one string

in if condition

System.Text.RegularExpressions.Regex.isMatch("ANDREW",String.Join("$|",Arr_Str))

And with only name we cant decide the gender and add the MR,MRS,etc to it

So it would be better if input has name, Age, gender with it based that we can assign the suffix to it

Regards
Sudharsan

Arr_Str={“MR”,“MISS”,“MRS”,“MS”}
string[4] { “MR”, “MISS”, “MRS”, “MS” }
Str=“WINIFREDMISS”
“WINIFREDMISS”
Arr_Str.Any(Function(v) Str.Contains(v))
true
Str=“ANDREW”
“ANDREW”
Arr_Str.Any(Function(v) Str.Contains(v))
false
Str=Str+“MR”
“ANDREWMR”

how to separate Title and name

I used this but not working
can you help please

Thank you for your quick response

Hi,

How about the following?

title = System.Text.RegularExpressions.Regex.Match(item,String.Join("|",arrTitle)+"$").Value
name = System.Text.RegularExpressions.Regex.Replace(item,title+"$","")

Sample20221107-4v2.zip (3.0 KB)

Regards,

HI,

Sorry, the following expression is better.

title = System.Text.RegularExpressions.Regex.Match(item,"("+String.Join("|",arrTitle)+")$").Value

Sample20221107-4v3.zip (3.0 KB)

Regards,