Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 16th, 2006, 07:48 PM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Find and Replace 2 characters at once!! HELP

Hi All... my brain is going to pop. I am writing a small application that allows you to cut and paste text from anything into a text box and then have it re-formatted taking out certain CRs and replacing them with others.

If it were a simple find and replace that would be no problem, but, this is what I want to do:

I want to find all instances of chr(34) and chr(46) (. & ") at the same time and replace them with . " # at the same time - make sense? (the reason I want to add the # is because I am going to newline that afterwards)

How can I find two characters together and replace with 3?

If I replace them seperately they will replace all instances of '.' (for instance) throughout the whole string. I only want to replace when the two (.") are next to each other.

here is some code I have been playing with - but it doesn't work as such! I must be close - the pain in my head tells me so ;)

Any tips much appreciated... Sco

---------------------------------------

firstfind = Chr(46) + Chr(13)
RemoveCharacters(TextBox1.Text, firstfind) >>> calls

    Public Function RemoveCharacters(ByRef strText As String, _
    ByRef strUnwanted As Char) As String
        Dim currLoc As Integer
        Dim StringLength As Integer
        Dim tmpChar As String

        StringLength = Len(strText)
        For currLoc = 1 To StringLength

            tmpChar = Mid(strText, currLoc, 2)
            If InStr(strUnwanted, tmpChar) Then
                Mid(strText, currLoc, 3) = Chr(46) + Chr(34) + Chr(35)
            End If
        Next

        RemoveCharacters = strText

    End Function



Reply With Quote
  #2 (permalink)  
Old March 17th, 2006, 11:18 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Fear not... I've cracked it! :)

Reply With Quote
  #3 (permalink)  
Old March 18th, 2006, 01:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Please post your solution so that others can benefit. Thanks.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best approach to replace characters with strings lumbrigack XSLT 8 June 16th, 2008 12:38 PM
Replace newline characters thomasjacob XML 1 May 2nd, 2006 04:06 AM
Find and replace? Stuart Stalker SQL Server 2000 8 October 13th, 2005 02:49 AM
Create a find and a find and replace in VB.NET snowy0 VB How-To 0 January 26th, 2004 07:03 PM



All times are GMT -4. The time now is 08:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.