-1

I have a string that is being passed from a web form as:

ABC_12345;DEF_78901

how can I get the prefixes of each value and then combine those and pass such as to SQL 'ABC','DEF'

  • What have you done and where are you stuck? Steering manipulation and database access are unrelated subjects. Break your problem down into parts and address each party separately. – John Aug 23 '22 at 14:35
  • I'm stuck with joining the two prefixes and setting as one variable to pass to my where clause in my SQL statement – JustWantsToCode Aug 23 '22 at 14:41
  • Are you actually stuck or have you not tried? It's a simple case of supporting a string and then joining strings. You really couldn't find any examples or information on doing that? – John Aug 23 '22 at 15:21
  • I have a for each loop to loop through all of the values, then removing the data from the [ _ ] on, which is working, however, when I join them, I'm getting the comma after the last value, so it looks like this: ABC,DEF, and I should see it as ABC,DEF If I try a for each loop with for i = 0 to tmp. then I get ABC, showing multiple times – JustWantsToCode Aug 23 '22 at 15:27
  • I don't see any loop in your question. You need to provide us with all the relevant information. We can't help you fix code we haven't seen. – John Aug 23 '22 at 15:30
  • It reads like you want to store CSV data in a column in a database: if that is the case, you should reconsider how the data is being stored: [Is storing a delimited list in a database column really that bad?](https://stackoverflow.com/q/3653462/1115360). – Andrew Morton Aug 23 '22 at 18:44

1 Answers1

0

First Split the string into Array

 Dim DBSplit1() As String
 DBSplit1 = YourString.Split(";")

 'Then get the the Prefix of you string

  Dim Result As New List(Of String)
    For Each item As String In DBSplit1
        Dim rs As String = item.Substring(0, 3)
        Result.Add(rs)
  Next

  'Then join the list of string with comma
  Dim StringResult As String = String.Join(", ", Result.ToArray())
Yat Fei Leong
  • 751
  • 1
  • 6
  • 10