PC Review


Reply
Thread Tools Rate Thread

A way to get "Like" to use "Option Compare Text" without changing the setting for all my code?

 
 
Linda
Guest
Posts: n/a
 
      29th Mar 2005
Hi,

Is there a way to do a "text" (rather than "binary") compareison with
the "like" operator, without changing the global "Option Compare"
setting? I don't want to risk breaking many, many lines of functional
code just to get one "like" operation to behave as I wish.

I want to check whether a single-character string is (a letter or
number, INCLUDING diacritical letters) or whether it is (something
else.)

if str1$ like "[A-Z]" or str1$ like "#" then
'blah blah blah
else
'blah blah blah
end if

....would work if I changed the source file's option to "text", but as I
said, I don't want to risk breaking the rest of the code. It's the need
to include diacritical letters in that makes this complicated,
otherwise I could just add an [a-z] comparison.

Is there another way to do this, or a way to make this work?

Thanks.

 
Reply With Quote
 
 
 
 
Linda
Guest
Posts: n/a
 
      1st Apr 2005
In case anyone is interested / faces a similar problem, here's how I
solved it:

In the library that I use for most of my applications, I created a
"TextCompare" class in it's own source file, which is Option Compare
Text. The class consists of public shared functions that simply invoke
the "like" operator and other comparison checks that reply on "Option
Compare".

(For my other source files, I've added an explicit "Option Compare
Binary" in addition to the obligitory "Option Strict On" and "Option
Explicit On" just so it's unambigous what's happening).

Now, if I want "Compare Binary" I do the comparison the standard way.
If I want "Compare Text" (and String.Compare() isn't appropriate) I
call the TextCompare static method.

=======================================================

Option Strict On
Option Explicit On
Option Compare Text

Public Class TextCompare

Public Shared Function txtEquals(ByVal str1$, ByVal str2$) _
As Boolean
Return str1$.Equals(str2$)
End Function

Public Shared Function txtLike(ByVal str1$, ByVal pattern$) _
As Boolean
If str1$ Like pattern$ Then Return True
Return False
End Function

Public Shared Function indexOf(ByVal outerStr$, ByVal innerStr$) _
As Integer
Return outerStr$.IndexOf(innerStr$)
End Function

Public Shared Function lastIndexOf(ByVal outerStr$, ByVal
innerStr$) _
As Integer
Return outerStr$.LastIndexOf(innerStr)
End Function

Public Shared Function startsWith(ByVal outerStr$, ByVal innerStr$)
_
As Boolean
Return outerStr$.StartsWith(innerStr)
End Function

Public Shared Function endsWIth(ByVal outerStr$, ByVal innerStr$) _
As Boolean
Return outerStr$.EndsWith(innerStr)
End Function

End Class

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shall I use an Event/Delegate way or just the compare value way? mesut Microsoft C# .NET 0 30th Jul 2008 09:10 AM
Microsoft Speech Recognition repeating error "all all all all all all...." kenrosen@gmail.com Windows XP General 1 17th Dec 2005 03:22 AM
Microsoft Speech Recognition repeating error "all all all all all all...." kenrosen@gmail.com Windows XP Help 0 16th Dec 2005 07:39 PM
Way To Copy Formula In Column Without Changing All Cell Numbers travelersway Microsoft Excel Misc 2 3rd Sep 2005 08:36 PM
Is there a way to compare array values without going through each element? Jim H Microsoft C# .NET 5 26th Jul 2004 05:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:14 AM.