Counter with split - help

HI,

I have a text …

varText =
Line1; This is my list of users;
Line2; Department name;
Line3: Anders;
Line3: ppr;
Line3; Tim;

splitText = Split(varText, “;”)

I have used split to get the value of each line… But I want that all users names from Line3 stored on one variable…

When I write splitText(6) it gives me Anders…

how can i get all username and store in one variable…

Hi

is Line1;
Line2;
are also part of the text

@Ellen

is a line seperator…
like line1 have differenet details…
Line 2 have different details…
Line3 will have all users name… but on different lines.

means how many users are involved then it will appear on line3

Split on VbCrLf not ;

Then use RegEx to get the value of splitText(2) between : and ;

No I mean
is the word “Line1” part of the text
or you kept to explain the scenario here

based on that i can share u the expression
@Ellen

line1 is part of text as welll…

1 Like

im not good at Regex and that way going for split.

If thats the case here you go the steps,

  1. use a assign activity like this
    str_input_1 = Split(varText,“Line3:”)(1).ToString

  2. then finally use a assign activity like this
    str_final = String.Join(“-”,Split(str_input_1.ToString, “;”))

Cheers @Ellen

maybe better to split on line break and then filtering it

Just put VbCrLf instead of “;” and you have your split.

Then Google “regex find string between two characters”

And use regex101.com to test it.

giving issue on first split

would recommend to type in again from your end rather than copying to clipboard from here
anyhow can u share the error u r getting @Ellen

Don’t copy/paste from the forum. You get the wrong double quote character. Type the expression yourself.

I wanted all usersname of Line3 but those assign is not giving me that… its output line1 and line2 with - instead on ; .

Thats not what i want… I have all the split… but I only need that when i come to line3 so in someway it loop through and add LINE3 user in one variable with a comma or ; .

like varUserName = Anders per, ppr, Tom hill, ect.

To get an array of strings with regex:

arrUsers = System.Text.RegularExpressions.Regex.Matches(varText, "(?<=Line3[:;] +)[^;:]+").Select(Function(m) m.Value).ToArray

Split(System.Text.RegularExpressions.Regex.Match(currentItem,"(?<=Line3)[:|;](.*)(?=;)").ToString," ")(1)

image

1 Like

Check this…
test.xaml (7.3 KB)

Hi @Ellen ,

Maybe we could try with the below Approach :

  1. Creating a Dictionary with the Mapped Names as Values.
dictLineNames = Regex.Split(strInput,"\r?\n").GroupBy(Function(x)Split(x,";")(0).Trim).ToDictionary(Function(x)x.Key,Function(y)String.Join(",",y.Select(Function(a)Split(a,";")(1))))

Here, dictLineNames is a Dictionary of type Dictionary(Of String,String) and strInput is variable of type String which is the Input text data.

Implementation :

From Debug Panel :

1 Like

Hi @Ellen,

You can able to Split the Word using either Regex Function of Split Operation to obtain the value

Hope this will be helpful !!

1 Like

Thanks … Its giving me names… I corrected the issue.

Just one question…
When its outputting the value its give an error message at the end means write after the last name… can you tell why its giving me that ??

Error: If: Index and length must refer to a location within the string. (Parameter ‘length’)