How to combine two lines in to one line

Hi All,

I have a an input string value as mentioned below

XXXX-XXX-1234
Sachin R Tendulkar
XXXX-XXX-0987
Suresh K Raina
XXXX-XXX-4567
Virender K Sehwag

I want the output value as

XXXX-XXX-1234 Sachin R Tendulkar
XXXX-XXX-0987 Suresh K Raina
XXXX-XXX-4567 Virender K Sehwag

Could you please help me with this.

Thanks,
Ragala.

Hi @Ragala

=> Assign activity

Input = "XXXX-XXX-1234
Sachin R Tendulkar
XXXX-XXX-0987
Suresh K Raina
XXXX-XXX-4567
Virender K Sehwag"

=> Use below Regex Pattern in Find Matching Patterns Activity:

Pattern: "[A-Z].*[\s\S]*?[A-Za-z].*"
Pattern Options: Compiled
Text to Search in: Input
Result: Matches

=> Use For Each loop

For Each currentMatch in Matches
   WriteLine -> currentMatch.ToString.ReplaceLineEndings(" ")
End For Each

Hope it helps!!

Hi @Parvathy
Thanks for your effort. After performing the actions as you said
The Final output value is coming as

XXXX-XXX-4567 Virender K Sehwag

But my final out put should be all three names along with their number

Thanks.

Hi @Ragala

Can you try the below

String.Join(Environment.NewLine, System.Text.RegularExpressions.Regex.Matches(Input, "(XXXX-XXX-\d{4})\r?\n([^\r\n]+)").Cast(Of System.Text.RegularExpressions.Match).Select(Function(m) m.Groups(1).Value + " " + m.Groups(2).Value))

Regards,

@Ragala

Another way

System.Text.RegularExpressions.Regex.Replace(Input, "(XXXX-XXX-\d{4})\r?\n([^\r\n]+)", "$1 $2")

Regards,

Hi @Ragala

Below syntax should help you.

Input = "XXXX-XXX-1234
         Sachin R Tendulkar
         XXXX-XXX-0987
         Suresh K Raina
         XXXX-XXX-4567
         Virender K Sehwag"

Output = String.Join(Environment.NewLine, System.Text.RegularExpressions.Regex.Matches(Input, "[A-Z].*[\s\S]*?[A-Za-z].*").Cast(Of System.Text.RegularExpressions.Match).Select(Function(m) m.Value.ReplaceLineEndings(" ")))

Let me know if you have any queries. I will help you.

Regards

Thanks @Parvathy it is working

Thanks @lrtetala Bro. It is working

Hi @Ragala

Glad to have helped.

Regards

Hi @Parvathy sorry to bother you. But I am pretty much impressed with the expression you gave. Does that expression came instantly from your mind or have you done any R&D for that. If yes can you please send me the source link how to get those expressions. Hope you don’t mind.

Thanks

Hi @Ragala

You can follow below videos

The regular expressions are written in below website. It is purely on pur requirement how we want the output.

For Linq you can follow below videos

If perfect, please close the topic by marking my post as solution.

Regards

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