Split and join same string


Lets say I have the string “Asanka El Camino” or “Asanka Camino”

Looking for the output of
“El Camino, Asanka” and “Camino, Asanka”

Keep in mind original string could be anything and could be 1 to 3 words.

Hi @Asanka

How u need to join the string ?


Please try this syntax

strText = “Asanka Camino”
String.Join(" “,Split(strText,” ").AsEnumerable.reverse.toarray)

Output = Camino Asanka

What about for “El Camino, Asanka”?
Can it be done in one? Say if its Asanka Camino or Asanka El Camino?

El Camino, Asanka” and “Camino, Asanka”

Assuming this

  1. test=“Asanka Camino” or “Asanka El Camino”
  2. test.Substring(test.IndexOf(" "))+","+test.Split(" "c)(0)

Hi @Asanka

I am confused by what order it should join

One case it is joining by reverse other by some other way

For “El Camino, Asanka” use String.Join(" “,Split(strText,”,").AsEnumerable.reverse.toarray)
For “Asanka Camino” use String.Join(" “,Split(strText,” “).AsEnumerable.reverse.toarray)
For “Asanka El Camino” we should have atleast have 2 spaces between asanka and El camino use String.Join(” “,Split(strText,”

Hey it worked! Thanks so much!

1 Like

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