Micro Focus QTP (UFT) Forums
Splitting Names F/M/L and sometimes F/L - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Splitting Names F/M/L and sometimes F/L (/Thread-Splitting-Names-F-M-L-and-sometimes-F-L)



Splitting Names F/M/L and sometimes F/L - Brian.Osborne - 06-03-2011

I need to split Names that are captured with my QTP script. I need to be able to use FirstName, MiddleName, and LastName independently.
The Issue is, sometimes the MiddleName is missing.
Is there a way to look at the right most characters till the space and call this first name, then look at the left most characters till the space and call this last name?


RE: Splitting Names F/M/L and sometimes F/L - UFTEnthusiast - 06-03-2011

Hello there!

Can you please send the sample name you want to Split. or sample code would also helps.

THanks


Thanks,

UFTEnthusiast


RE: Splitting Names F/M/L and sometimes F/L - suresh vasu - 06-03-2011

Hi Brian,

No need to look for right most or left characters to handle the situation, Just checking with an If condition would solve your problem. Below is the code I ve written to suit your requirement.

Code:
Function splitNames(str)

splitNames = split(str," ")
  
End Function

strName = splitNames("Suresh Vasu Kondapally")
IF UBound(strName)<2 Then
MsgBox "First Name :"&strName(0)&", Middle Name : Not Entered"&", Last Name :  "&strName(1)
Else
MsgBox "First Name :"&strName(0)&", Middle Name : "&strName(1)&", Last Name :  "&strName(2)
End IF


You can put "/" if you want in the name as you asked F/M/L, in place of space " ". But dont forget to replace that at both the places that is when sending an argument and at split keyword in the function.

Thanks,
Suesh.