Input in my case is a string with a list of elements separated by Comma
Input:
var input = "123,456,789";
Expected Output (a string):
"'123','456','789'"
I'm looking for a solution in VB.net but i'm not so familiar with it. So, I tried it in c#. Not sure what i'm missing.
My Attempt:
var input = "123,456,789";
var temp = input.Split(new Char[] { ',' });
Array.ForEach(temp, a => a = "'" + a + "'");
Console.WriteLine(String.Join(",",temp));
Actual Output:
"123,456,789"
Any help in funding a solution in vb.net is much appreciated :)
append(char[] str) method appends the string representation of the char array argument to this sequence. The characters of the array argument are appended, in order, to the contents of this sequence. The length of this sequence increases by the length of the argument.
If you are using array module, you can use the concatenation using the + operator, append(), insert(), and extend() functions to add elements to the array. If you are using NumPy arrays, use the append() and insert() function.
To store the words, a 2-D char array is required. In this 2-D array, each row will contain a word each. Hence the rows will denote the index number of the words and the column number will denote the particular character in that word.
In C, char* means a pointer to a character. Strings are an array of characters eliminated by the null character in C.
You could use LINQ:
var result = string.Join(",", input.Split(',').Select(x => "'" + x + "'"))
This splits the string at the ,
delimiter, then adds the quotes around the pieces using Select()
, and then reassembles the array using string.Join()
Edit: Here is the equivalent VB.NET solution:
Dim result As String
result = String.Join(",", input.Split(",").Select(Function (x) ("'" & x & "'" )))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With