Solved How to Split String Using Regex Expressions

f04959c

New Member
Hello,

I need to split a string using uppercase character

So, for example:

String:
"GiornoFest.Err.EntrataUscitaEntrataUscitaAltreCausaleDalleAlleDurata

Collection:
"Giorno
Fest.
Err.
Entrata
Uscita
Entrata
Uscita
Altre
Causale
Dalle
Alle
Durata

Thanks
Ale
 

sivagelli

Well-Known Member
This is how I approached the problem statement. I inserted a delimiter (space) before a uppercase character and used 'Split Text' action from the Utility Strings VBO to make the string in to collection.

You need a code stage for executing the regex.

Add below Namespaces to 'Code Options' Tab on the Initialize page of the object-

System.Text
System.Text.RegularExpressions

Global Code:

C#:
public string AddSpacesToString(string text)
{
    return Regex.Replace(text, @"((?<=\p{Ll})\p{Lu})|((?!\A)\p{Lu}(?>\p{Ll}))", " $0");
}

Now, call the above function with Code stage:

  1. Start
  2. Code Stage:
    • Under Inputs tab, have an input parameter of Text type. Lets say input string 'inputStr'
    • Under Outputs tab, have an output parameter of Text type. Lets say input string 'outputStr'
    • Under Code tab: outputStr = AddSpacesToString(inputStr);
  3. 'Split Text' action from Strings VBO
    • Inputs:
      • Text to Split: [outputStr]
      • Split Char: " "
      • Collection Field Name: "Values"
    • Output:
      • Split Values: SplitCol
  4. End

On execution of the above flow, you will have the 'SplitCol' with the desired output.

Post back how it goes.
 

srikanthp

New Member
Hello Siva,
I have a similar situation where I have collection of strings and I need to process all the strings one by one to extract the numbers. can you suggest me a better approach in handling that situation?

Thanks!
 
Top