Counter with split - help

You probably have a blank line at the end so currentItem.Substring(0,5) is causing an exception.

Change it to…

CurrentItem.Length > 5 AndAlso currentItem.Substring(0,5) = “Line3”

That way it’ll only process the currentItem.Substring(0,5) if the length is over 5.

Thanks It had a blank line… when i removed it didt show any error…

I want to know one thing… Im using this regular expression instead of yours as its simple…

System.Text.RegularExpressions.Regex.Match(currentText,“[A-z]+\s[A-z]+\s[A-z]+”).ToString

but I have one issue with that… and its. if name is like…

Anders
Anders Morten
Tim Morten Andersen
Tomy Andersen

Then the regular expression I’m using is showing only name ( Tim Morten Andersen) and its not showing 1,2 and 4th user name.
Which is also correct as its matching [A-z]+ only one user with 3 name part…

How can i make this regular expression so that it both show value of either its only writen Anders or Anders Morten or Tim anders Morten andersen or Tomy andersen.

Your this expression is good but its shows me more value out and I dont want to use split again.
System.Text.RegularExpressions.Regex.Match(currentText,“(?<=Line3);(?=;)”).ToString

I made a mistake in my RegEx and had the : or ; outside the initial grouping. This is simpler:

(?<=Line3[:|;] )(.*)(?=;)

If the fact that you have both : and ; after Line3 is just a typo, and it’s always : then just use…

(?<=Line3: )(.*)(?=;)

With both of those you won’t need the additional split around it.

1 Like

can you explain what (.*) stands for…

and is (?=;) reffer to the last ; of each line?

Have one question related to that…

My result form that Regex in forech loop is 3 name…
Now I want to store all those name into SQL… What is the best way to do and how to do??

(.*) means get everything

" is (?=;) reffer to the last ; of each line?"

Yes

Go to regex101.com and paste in the regex expression and your test string. You can mouse over each element and it’ll tell you what it does.

Use the Add Data Row activity to add them to a datatable. Then use that datatable with the Insert activity.

I tried with list of string but having issue with writing into database…

Variable
ListOfUsers - datatype - List

Assign
ListOfUsers = New list(of String)

Assign
ListOfUsers = ListOfUsers.append(UsersName).ToList

when im writing SQL query…

Insert into TABLE
(InvoiceID, UserNames)
Value (@invoiceId, @listofUsers)

My parameter is
@listofUsers - In - List - ListOfUsers
@InvoiceId - in - String - varInvoiceid

It’s giving me errror:
Execute Query: No mapping exists from object type System.Collections.Generic.List[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] to a known managed provider native type.

Can you help with that…

I tried with database as well as you said … Its working means I had success with writting all usernames into one DB column.

Result in DataBase column shows as:
ListOfUserNames Anders ppr tim

Issue is:
It’s adding buildDT column name “ListOfUserNames” into DB column with 3 usernames as well.
Plus I needed a comma in between each name så that it seperate and show that this column holds three person name.

You don’t insert a list directly into a SQL database. You loop through the list and use Add Data Row to put them into a datatable then you pass that datatable to the Insert activity.

If you want to insert the list into one column in a database row, then use String.Join on the list to make it a comma delimited string, and use that in your insert query.

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