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.
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.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naveen KumarRank #249 · 10K reputationPosted Oct 9, 2024, 8:54 AM EDT
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)PinkuRank #3,922 · 378 reputationPosted Oct 9, 2024, 9:15 AM EDT
Thank you so much Navin. ACtuaaly i need this. I was trying something. SO thank you once again.