Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 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 November 9th, 2007, 01:35 AM
Authorized User
 
Join Date: Oct 2006
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ricespn
Default STRING EXACT MATCH

Hi guys,

Is there a way that I can compare a string against a list to see if it mathces and if it does change that string?.

This is what I have:

   WORD LIST ABBREVIATION
ASSIGNMENT ASGMT
ASSIGNMENT ONE ASGMT O
ASSIGNMENT TWO ASGMT T
ONE ON
TWO TO

I have to compare the word list column against the string and replace that word or words for the abbreviation. Let say that my string is: ASSIGNMENT ONE 99876

If I use REPLACE ("ASSIGNMENT ONE 99876", WORD LIST, ABBREVIATION) I get this result : ASGMT ONE 99876 instead of ASGMT O 99876

if I use "ASSIGNMENT ONE 99876 = WORD LIST" nothing happens because the whole string is not on the list

I was thinking of something as an exact match but I can't find anything on the net.

Any Ideas I'll appreciate it...

Thanks!

=======================
Strange and crazy, but everything is possible
__________________
=======================
Strange and crazy, but everything is possible
 
Old November 9th, 2007, 08:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hi there..

are you passing the whole list to the replace function?? is there a overcharged method that I don't remember???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old November 9th, 2007, 11:21 AM
Authorized User
 
Join Date: Oct 2006
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ricespn
Default

Hi gbianchi,

Yes I have to compare the whole list of words against the string and replace the words as I find them.

=======================
Strange and crazy, but everything is possible
 
Old November 9th, 2007, 12:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

ok.. you are in vb6?? replace parameters are:
string to look into
string to change
string to change to...

so would like to see have are you coding this. Also your aproach has a very good problem in your test case, because it will try to replace the string in orders it found, making it fail because you have 2 origin string that start the same...

your example was good from the point of view of vb(it replace the string).. replace only look for strings.. not tables or arrays of examples..

did you follow me??



HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old November 12th, 2007, 12:05 PM
Authorized User
 
Join Date: Oct 2006
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ricespn
Default

gbianchi,

The list is in memory as an array, after the user has done the input I use the Lost Focus event fro that text box then I compare every item fom the list agaist the string and I replace the word using the replace function.

This is the code I have:

Private Sub txtIndex4_LostFocus()
Dim intSearch As Integer
        txtIndex4.Text = Replace(UCase(txtIndex4.Text), "'", "")
        For intSearch = 0 To intListCount
            If Trim(txtIndex4.Text) = strWordAbbreviations(intSearch, 1) Then
                txtIndex4.Text = strWordAbbreviations(intSearch, 2)
            End If
        Next intSearch
        Call constructIndex
end sub
Private Sub constructIndex()

Dim intSearch As Integer
txtDocumentDescription.Text = UCase(Replace(Trim (lblDocumentAbbreviation.Caption) & " " & Trim(txtIndex1.Text) & " " & Trim(txtIndex2.Text) & " " & Trim(txtIndex3.Text) & " " & Trim(txtIndex4.Text) & " " & Trim(txtIndex5.Text) & " " & Trim(txtIndex6.Text) & " " & Trim(txtIndex7.Text), " ", " "))

For intSearch = 0 To intListCount
txtDocumentDescription.Text = UCase(Replace(txtDocumentDescription.Text, " " & strWordAbbreviations(intSearch, 1) & " ", " " & strWordAbbreviations(intSearch, 2) & " "))
Next intSearch

End Sub


=======================
Strange and crazy, but everything is possible
 
Old November 12th, 2007, 12:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hey there...

I don't fully understand the idea of your code.. but you still have the same problem...

the way you do the replace is your problem.. you have to always look first for the longest case, the problem you are facing is the order you look for the replace.. look what happens is you invert your array...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old November 12th, 2007, 01:18 PM
Authorized User
 
Join Date: Oct 2006
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ricespn
Default

gbianchi,

I know what you are saying, the code is removing any double space in the string, just in case that the user descides to insert extra spaces at the end, I have 7 fields that I need to check and replace words, so far the list contains 200 words and full sentences. This list resides as a table in SQL. I'll se if i can rearrange the table from the complete sentences to the single words.

Thanks for your help!

=======================
Strange and crazy, but everything is possible





Similar Threads
Thread Thread Starter Forum Replies Last Post
Search for a String Match combo Box tsadok VB Databases Basics 0 January 27th, 2008 02:24 AM
need to match string dynamically dipsut XSLT 2 May 25th, 2007 08:49 AM
match string in more than one line using Regex suman9730 General .NET 0 October 24th, 2006 02:27 AM
How to return a string to it's exact original (len EDCH123 Java Databases 0 January 25th, 2006 04:06 PM
Exact Match problem demiwolf XSLT 1 February 14th, 2004 10:28 AM





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