Ramudu
(Ramudu)
August 29, 2024, 3:51pm
1
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
pradeep931
(Pradeep Bandharam)
August 29, 2024, 4:07pm
2
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
lrtetala
(Lakshman Reddy)
August 29, 2024, 4:35pm
3
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,
SorenB
(Søren)
August 29, 2024, 6:00pm
4
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
vrdabberu
(Varunraj Dabberu)
August 29, 2024, 9:16pm
5
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
Ramudu
(Ramudu)
September 2, 2024, 2:47pm
6
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.
Ramudu
(Ramudu)
September 2, 2024, 2:49pm
7
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.
vrdabberu
(Varunraj Dabberu)
September 3, 2024, 4:09am
8
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
Ramudu
(Ramudu)
September 4, 2024, 7:06am
9
Hello @vrdabberu ,
Thank you!!!
I will give few example anove is not working.
Input : expected output(1st namr, middle and last name)
Mr. John W. Verde : Mr. John, W. and Verde
Mr. Jackson : Mr. Jackson (only 1st name)
Mrs. Dana Lozito : Mrs. Dana (1st name) and Lozito(last name)
vrdabberu
(Varunraj Dabberu)
September 4, 2024, 10:56am
10
Hi @Ramudu
check with the below attached xaml and let me know if any changes required.
Sequence50.xaml (8.0 KB)
Regards
Ramudu
(Ramudu)
September 6, 2024, 2:31pm
11
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
Ramudu
(Ramudu)
September 6, 2024, 2:34pm
12
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