How to split multiple split character options

Hey!

I have variable1 = str_name.Split("-"c)(1)

Incoming variables are type of firstname-surname, but it can be also firstname+surname so how I get my variable split also the “+” character?

2 Likes

Hey, @Finnn
Welcome!

you want
FirstName
LastName
and Split Character?
@Finnn

No I want only the LastName and only problem is the “+” character sometimes instead of “-” how to add it in my variable as option that its sometimes “-” and sometimes “+”

stringVar.split({" "c,vblf},StringSplitOptions.RemoveEmptyEntries)
or
" firstname+surname".Split({“+”,“-”},StringSplitOptions.None)
did you try this??
@Finnn

@Finnn
in such scenario a regex statement can help

Hi @Finnn,

If there is multiple situations like + and -, please use Regular Expression to extract surname. Syntax will be as follows -
System.Text.RrgularExpressions.Regex.Match(str_YourStringVariable, “(?<=(\+|\-)\s*)[A-Za-z]+”).ToString.Trim

Thanks & Regards,
Apurba

2 Likes

arrayVar = “firstname+surname”.Split({“+”,“-”},StringSplitOptions.None)
this will give you System.String[ ], so if you want lastName you can get it like this arrayVar(1)

this will work for you!
cheers
@Finnn

2 Likes

I will try that when I get back from lunch, but I forget mention that firstname lastname thing is one total variable. From which I need the lastname part only.

@apurba2samanta I try that too

2 Likes

in that case you can use above mentioned method!
@Finnn

as @apurba2samanta said you can use regex expression to extract surname .

you can do this!

  • use Matches Activity and pass your str_Name as input ,
    and pass this pattern (?<=(+|-)).[A-Z]* and get output like outSurname

  • To print surname outSurname(0).ToStrin using MessageBox/Writeline

Cheers
@Finnn

Yea @Finnn,

I suggested the Regular Expression for your variable, containing First name & Last name.

Thanks & Regards,
Apurba

I got it work with variable= str_name.Split({“+”,“-”},StringSplitOptions.None)

I got the surname I wanted now I want 3rd number of it and if its even I know he’s boy and not even =girl which I check by converting it into int32 and using if mod 2. I tried get 3rd character with substring but got an issues with it: variable name = str_name.tostring.Substring(3,1)

Thanks @Pradeep_Shiv

can you give example with names??
@Finnn

I have Martin-Brodeur-1234 and I want that 3rd number as int so I can if mod check it.
It can also be Yanica-Djokovic-1224

it can also be Martin+Brodeur+1234 and same for female example

so you are checking Martin+Brodeur+12"3"4 number right??

1 Like

Sequence.xaml (5.4 KB)

Try this!
Cheers
@Finnn

1 Like

Yes thats what I was lookking for, thx @Pradeep_Shiv !

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.