2
Answers

How to concat string in between another string in vb.net

Pinku

Pinku

Oct 09
435
1

I have a string value but i want to add "[^a-zA-Z0-9 ]%" with the string after the first word.
for ex: string S1='sustainability energy long last'

I want to add like : sustainability[^a-zA-Z0-9 ]%  energy long last

How to do it.

Answers (2)
4
Naveen Kumar

Naveen Kumar

162 11.8k 283.7k Oct 09

In VB.NET, you can concatenate or insert a string at a specific position by using the Insert method. Since you want to insert the substring [^a-zA-Z0-9 ]% after the first word, you can find the position of the first space and insert the string at that location.

But do you really want to insert a REGEX "[^a-zA-Z0-9 ]%"?

Check the below code:

Dim s1 As String = "sustainability energy long last"
Dim insertText As String = " [^a-zA-Z0-9 ]%"
Dim firstSpaceIndex As Integer = s1.IndexOf(" ")

If firstSpaceIndex >= 0 Then
    s1 = s1.Insert(firstSpaceIndex, insertText)
End If

Console.WriteLine(s1)
Accepted
1
Pinku

Pinku

1.4k 319 50.9k Oct 09

Thank you so much Navin. ACtuaaly i need this. I was trying something. SO thank you once again.