?
Solved

How do i replace multiple characters in a string using vb.net

Posted on 2010-03-23
8
Medium Priority
?
676 Views
Last Modified: 2013-11-07
I want to replace multiple characters in a string.
presently im doing this shown in code.

I want to be able to replace the string with multiple known chars like, "<b>" ,"</b>", "<p>", <br> with empty string "".
Please suggest with code.
Dim txtVal  as String
txtVal= txtVal.Replace("<BR>", "")

Open in new window

0
Comment
Question by:nirisan
8 Comments
 
LVL 61

Expert Comment

by:HainKurt
ID: 28396142
try this
Dim txtVal  as String
txtVal= txtVal.Replace("<BR>", "").Replace("<b>","").Replace("</b>","")...

Open in new window

0
 
LVL 61

Expert Comment

by:HainKurt
ID: 28396177
or
Dim txtVal  as String
txtVal= txtVal.Replace("<BR>", 
txtVal= txtVal.Replace("<b>","")
txtVal= txtVal.Replace("</b>","")
...

Open in new window

0
 

Author Comment

by:nirisan
ID: 28397010
thanks for your reply, but is possible to put in through a loop and give toReplace parameters.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:nirisan
ID: 28397058
thanks for your reply, but is it possible to put it in a loop and give toReplace parameters?
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 28397214
0
 
LVL 39

Expert Comment

by:appari
ID: 28403894
try like this

        Dim a As String = "<br>test<b>wew><</b>wewewew</br><i>wewe</i>", a1 As String
        Dim strReplace As String() = {"<br>", "</br>", "<b>"}
        a1 = String.Join("", a.Split(strReplace, StringSplitOptions.None))
0
 
LVL 61

Accepted Solution

by:
HainKurt earned 2000 total points
ID: 28411743
something like this
    Public Shared Function MultiReplace(ByVal s As String, ByVal r As String, Optional ByVal w As String = "") As String
        Dim str As String = s
        For Each i As String In r.Split(",")
            str = str.Replace(i, w)
        Next
        Return str
    End Function

use like

str = MultiReplace(str, "<br>,<BR>,</b>,<i>,</i>,</br>", "")

Open in new window

0
 

Author Closing Comment

by:nirisan
ID: 31706365
Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
An ASP.NET Web Form User Control is not newly introduced in ASP.NET. In fact, it was an old technology yet still playing a role to generate web content, especially when we want to use it to have a better and easy way to control part of the web conte…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
If you are looking for an automated solution for backup single or multiple Office 365 user mailboxes to Outlook data file, then you can use Kernel Office 365 Backup & Restore tool. Go through the video to check out the steps to backup single or mult…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question