0

How can I assign a split parts of a string into an array list directly ?

String format:

ABC;PQR;XYZ

2 Answers 2

3

Not sure what you want but doesn’t the following serve your purpose?

Dim input As String = "ABC;PQR;XYZ"
Dim x As New List(Of String)(input.Split(";"c))

Notice that I’ve used the superior List<String> (from System.Collections.Generic) instead of the deprecated ArrayList.

Also, do you really need a modifiable List? Unless you want to add or remove entries, a plain array should be fine.

Sign up to request clarification or add additional context in comments.

3 Comments

Actually one my hashtable value is ABC;PQR;XYZ, i need to assign it to an arraylist so that i can process the values one by one.
@Santhosh_ms3 your question mentions nothing about a hashtable, and your comment doesn’t clarify at all. How doesn’t my answer do what you want? Why do you need an (array)list anyway? You can process values in an array one by one.
Yes this split section is present inside the foreach loop and everytime if i encounter value from hastable contains ";" i need to split them and assign it to an array for further processing.
0
    Const XHundred = ",C,CC,CCC,CD,D,DC,DCC,DCCC,CM"
    Const Xten = ",X,XX,XXX,XL,L,LX,LXX,LXXX,XC"
    Const Xone= ",I,II,III,IV,V,VI,VII,VIII,IX"

I used this in a function. then later at the end of the function I used split() to split these into string arrays.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.