Need help in splitting a string

Hi People,

Need some guidance on below scenario

Suppose I have a text value like → axftrbc.10111.111.0101

I want the output to be only → axftrbc

I also want to check if the original text contains a .(dot) or something like the format or anything to ensure when i split it do not break, then i want to split it and get this first server value → axftrbc.

Looking for some solutions.

Thanks!

Hi,

How about the following?

System.Text.RegularExpressions.Regex.Match(yourString,"^.*?(?=\.)").Value

OR

System.Text.RegularExpressions.Regex.Match(yourString,"^\w+").Value

Regards,

1 Like

HI @Yoichi

Thanks for this.

Will this also work if the text axftrbc.10111.111.0101 changes to this → axftrbc.10111.111.0101.111.1234.12345 meaning increasing in values post .(dot)?

1 Like

HI,

Do you mean you also want to extract “axftrbc” from “axftrbc.10111.111.0101.111.1234.12345”? If so, the above expression also works for it.

Regards,

Ok thanks I will test and let you know the results

Hi @Yoichi,

I am getting some error when I am using this.

In my use case I want to use it in a invoke code activity, something like below(example)

dt.AsEnumerable.ToList.ForEach(Sub(row)
    If row("Host name").ToString.equals("abcdef.1101101.191.10") Then
        row("Host name")=row("Host name").Replace("abcdef.1101101.191.10","abcdef")
    End If
End Sub
)

Here If Host name column contains the above regex matching value ->abcfdr.11011.1101.11 this one then i want to replace it with that first value → abcfdr

I tried your code by incorporating in invoke code but it is giving compilation error.
Can you please help here.

Thanks

Hi,

Can you share screenshot with error message?

Regards,

yes,

I think I am doing wrong.

Thanks

Hi,

I’m not sure it’s fit your requirement, but can you try to use the following condition in If statement in line 2? Probably warning will be disappeared.

System.Text.RegularExpressions.Regex.IsMatch(yourString,"^.*?(?=\.)")

Regards,

var.split("."c).toarray(0).tostring

try this one

“axftrbc.10111.111.0101”.SPLIT(“.”/C).FIRST

Hello @Dhruvi_Arumugam

If you are trying to get the first value before to the dot in the string, its better to use the Split method.

Split(YourString,“.”)(0)

This will give you the first value.ie, axftrbc

Hello @Dhruvi_Arumugam Please modify the if condition expression like below

If System.Text.RegularExpressions.Regex.IsMatch(row("Host name").ToString,"^.*(?=\.)")

Now, see if that issue still appears