Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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



 
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! :)

 
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.




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





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