Re: Boolean logic on strings?

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Bob Butler (tiredofit_at_nospam.com)
Date: 11/15/04


Date: Mon, 15 Nov 2004 10:05:29 -0800


"Rex Shudde" <0024p@vm1.cc.nps.navy.mil> wrote in message
news:O0zRLuzyEHA.1296@TK2MSFTNGP10.phx.gbl
> Is there any way to do Boolean logic on *long* strings in VB6? For
> example, given the two strings
> x$ = "1000010000"
> y$ = "0001010010"
> I would like to set
> z$ = x$ Or y$
> which should result in
> z$ = "1001010010"
> not
> z$ = "1000339802"
>
> Also setting
> w$ = x$ And y$
> should result in
> w$ = "0000010000"
> not
> w$ = "680208"
>
> The VB Help file, when looking under the AND or OR logical operators,
> says that the expressions must be numeric, but I get the same results
> whether numeric or string. Also, these results are contrary to the
> truth tables given in the Help file.
>
> I need to perform these logical operations on 0/1 strings of length
> 100 or greater. Any help would be appreciated.

You are getting the starnge results because VB is converting the strings to
numbers, doing the And or Or operation and then converting the result back
to a string. To avoid that you'll need to loop through the characters and
doing each byte individually
z=space$(len(x))
for i=1 to len(x)
  mid$(z,i,1)=cstr(clng(mid$(x,i,1)) Or clng(mid$(y,i,1)))
next

-- 
Reply to the group so all can participate
VB.Net... just say "No"


Relevant Pages

  • Re: function
    ... The logical operators all return 1 to mean true and 0 to mean false. ... when x is a pointer, ... the two strings were the same. ... the strcpy() that you had above the test, ...
    (comp.lang.c)
  • Boolean logic on strings?
    ... Is there any way to do Boolean logic on *long* strings in VB6? ... The VB Help file, when looking under the AND or OR logical operators, ...
    (microsoft.public.vb.general.discussion)
  • Unicode USB strings conversion
    ... In the USB code unicode ... characters in strings are converted in a very crude way to ASCII. ... attempts at making the kernel use UTF8. ... of converting LE and BE UTF8 to ASCII. ...
    (freebsd-hackers)
  • Re: Math
    ... converting them to strings, then back, the precision will be lost. ... string is performed by the C compiler, whence Perl is at the mercy of ...
    (comp.lang.perl.misc)
  • Re: Speed comparison of regex versus index, lc, and / /i
    ... "index" is better for matching fixed strings than using regular ... As a test of the proposition that index is better than regexes, ... doing the matching, rather than converting the strings using lc, saved ... spent converting to lower case. ...
    (comp.lang.perl.misc)