Hoa to separate the data from the string

Hi Team,

Input string : Jan F. Farrell

Need to separate above string into 3 parts.

Output like this
First name : Jan
Middle name : F.
Last name : Farrell.

If input also like this
Beth Ann Smith or Andrew Tran

If input string has “.” That means string have middle name other wise consider as first name
Output1 :
first name : Beth Ann
Last name : Smith
Output 2:
First name : Andrew
Last name : Tran.

Kindly suggest with linq query

Hello @Ramudu

Why can’t you try with split operations simply split it with space

arr = split(input," ")
arr index values gives the your desired output

Hi @Ramudu

firstName = String.Join(" ", inputString.Split(" "c).Take(inputString.Split(" "c).Length - If(inputString.Contains("."c), 2, 1)))
middleName = If(inputString.Contains("."c) AndAlso inputString.Split(" "c).Length > 2, inputString.Split(" "c)(1), "")
lastName = inputString.Split(" "c).Last()

Regards,

Hello @Ramudu

I would simply split the name into an array of strings.

arr_NameSections = str_Name.Split(" ",StringSplitOptions.RemoveEmptyEntries)

And then check to see if it has 3 “parts” or more, to determine if there is a middle name present.

If arr_NameSections.Count > 3

Afterwards you can get the sections by defining the index in the array.

str_FirstName = arr_NameSections(0)
str_MiddleName = arr_NameSections(1)
str_LastName = arr_NameSections(2)

Best regards
Soren

Hi @Ramudu

Use the below syntax in Assign Activity:

Assign activity -> input = "Jan F. Farrell"
Assign activity -> names = input.Split(" "c)
Assign activity -> firstName = String.Empty
Assign activity -> middleName = String.Empty
Assign activity -> lastName = String.Empty

Use the below condition in If:

If
  names.Any(Function(name) name.Contains("."))
Then
  Assign activity -> firstName = names.First()
  Assign activity -> middleName = names.FirstOrDefault(Function(name) name.Contains("."))
  Assign activity -> lastName = names.Last()
  Write Line -> "First name: " + firstName + Environment.NewLine + "Middle name: " + middleName + Environment.NewLine + "Last name: " + lastName
Else
  Assign activity -> firstName = String.Join(" ", names.Take(names.Length - 1))
  Assign activity -> lastName = names.Last()
  Write Line -> "First name: " + firstName + Environment.NewLine + "Last name: " + lastName
End If

FLOW:

VARIABLE DATATYPES:

XAML:
Sequence9.xaml (12.0 KB)

OUTPUT:

Regards

Hello @vrdabberu ,

Its working fine for few names. But the problem is
Sometimes the name contains Jackson Inc. so above code consider inc. as middle and last name.

If middle name contains only letter along with .

For example Jackson S. Larry
Middle name will be S.
Middle name contains only one letter.

Jackson Inc.

Another example : Jackson Inc.
Above code consider 1st Jackson
Middle and last name will be Inc.

I want to output is 1st name Jackson
Middle wil be empty
Last name is Inc.

Hi @Ramudu

Use the below syntax in Assign Activity:

Assign activity -> input = "Jan F. Farrell"
Assign activity -> names = input.Split(" "c)
Assign activity -> firstName = String.Empty
Assign activity -> middleName = String.Empty
Assign activity -> lastName = String.Empty
Assign activity -> potentialMiddleName = names.FirstOrDefault(Function(name) name.Contains(".") And name.Length = 2)

Use the below condition in If:

If
  potentialMiddleName IsNot Nothing
Then
  Assign activity -> firstName = names.First()
  Assign activity -> middleName = potentialMiddleName
  Assign activity -> lastName = names.Last()
  Write Line -> "First name: " + firstName + Environment.NewLine + "Middle name: " + middleName + Environment.NewLine + "Last name: " + lastName
Else
  Assign activity -> firstName = String.Join(" ", names.Take(names.Length - 1))
  Assign activity -> lastName = names.Last()
  Write Line -> "First name: " + firstName + Environment.NewLine + "Last name: " + lastName
End If

FLOW:

VARIABLE DATATYPES:

XAML:
Sequence9.xaml (12.4 KB)

OUTPUT:

Regards

Hello @vrdabberu ,

Thank you!!!

I will give few example anove is not working.

Input : expected output(1st namr, middle and last name)

  1. Mr. John W. Verde : Mr. John, W. and Verde
  2. Mr. Jackson : Mr. Jackson (only 1st name)
  3. Mrs. Dana Lozito : Mrs. Dana (1st name) and Lozito(last name)

Hi @Ramudu

check with the below attached xaml and let me know if any changes required.
Sequence50.xaml (8.0 KB)

Regards

Hello @vrdabberu ,
Thank you!!!

I am getting the correct output as i expected but
But here i need to store the 1sg name. middle name and Last name values in different variables.

I want to store the data in different variables.
For each iteration the output will stored in only ine variable.

I didn’t understand how to store the names in 1 or 2 or 3 variables based on input name.
Kindly suggest

Note : here 1 or 3 or 2 means

If input data contains only 1st name like
Jackson bot need to store the 1st name remaining middle and last name Variables will be empty.

If input contains 2 like Mr. Jackson Jared then bot will store the 1st name and last name variables and middle will be empty like this