Implement the hypens in the given information

I have an information like,
AMEPVH005
AMEX1000
AMEP4712
Result:
Want the outcome as
AMEP-VH005
AMEX-1000
AMEP-4712

Cheers!
Happy Automation

@Iswarya_P1

Try this

Say the string is stored in str then

Newstr = Str.Insert(4,"-")

Hope this helps

Cheers

2 Likes

Hey @Iswarya_P1 ,

You can try text.Replace(text.Substring(0,4),text.Substring(0,4)+β€œ-”)

@Iswarya_P1

[Input].Substring(0, 4) + β€œ-” + [Input].Substring(4)

if I have a information as
AMF5000

in this case, how should I add hyphens?

Cheers!

First use an if condition,
if Regex.Match(text,"[a-zA-Z]+").Value.ToString.Length < 4,

perform text.Replace(Regex.Match(text,"\d+").Value.ToString,"-" + Regex.Match(text,"\d+").Value.ToString)

else perform text.Replace(text.Substring(0,4),text.Substring(0,4)+"-")

1 Like

@Iswarya_P1

On what basis you want to add hyphen?

Is it not based on number of characters? If so can you tel the logic to f adding it because i see the first one you have you separater a letter as well instead of only number…

Is it like max 4 characters or till the letters are found?

Cheers

1 Like

Hi @Iswarya_P1

Use the below workflow

=> Assign -> StrVar = "AMEPVH005"
=> Assign -> ReplaceValue = System.Text.RegularExpressions.Regex.Replace(StrVar.ToString,"([A-Z]{4})","-")
=> Assign -> StrVar = StrVar.Substring(0,4)+ReplaceStr

Hope it helps!!

1 Like

I have information as, a combination of
AMEPVH005
AMEX1000
AMEP4712
AMF5000
Result:
Want the outcome as
AMEP-VH005
AMEX-1000
AMEP-4712
AMF-5000

The above-mentioned are possibilities,
Cheers,

@Iswarya_P1

Code.Length<=7
Code.Substring(0, 3) + β€œ-” +Code.Substring(3)
else
code.Substring(0, code.Length - 3) + β€œ-” + code.Substring(code.Length - 3)

@Iswarya_P1

try this If(System.Text.RegularExpressions.Regex.Match(str,"[A-Z]*").Value.Count>4,System.Text.RegularExpressions.Regex.Replace(str,System.Text.RegularExpressions.Regex.Match(str,"[A-Z]{4}").Value,System.Text.RegularExpressions.Regex.Match(str,"[A-Z]{4}").Value + "-"),System.Text.RegularExpressions.Regex.Replace(str,System.Text.RegularExpressions.Regex.Match(str,"[A-Z]*").Value,System.Text.RegularExpressions.Regex.Match(str,"[A-Z]*").Value + "-"))

cheers