Regex code needed for seprating a string of first name and last name

The string is Input

Karthi keyan
Prasana p.prem
Ajay A.kumar

Output
First name
Karthi
Last name
Keyan

First name
Prasanna
Last name
P.prem

Can anyone help me with some regex code

@Karthikeyan34
If it’s just a first name and a last name separated by a space you don’t need Regex. For each line you can do line.Split(" "c).First for the first name and line.Split(" "c).Last for the last name.

Sure, what do you need as a output?

Input is
karthi keyan
output needed is
First name
Karthi
last name
keyan

@srdjan.suc can you help me with some regex

Thanks @DanielMitchell but still i got the first name but i didnt get the last name …

No need for regex there, you can use Split String method as mentioned above

What did you get instead of the last name?

I am just getting a it as empty

Where the message box displayed is empty @DanielMitchell

Try line.Split(" ".ToCharArray,StringSplitOptions.RemoveEmptyEntries) for the split part of the function. It’s possible that you have extra spaces in your string.

I got it Thanks @DanielMitchell

1 Like