1. type string(sequence s)

Is there a better way to do this?

type string(sequence s)
    for i =3D 1 to length(s) do
        if not (s[i] >=3D 0 and s[i] <=3D 255) then
            return 0
        end if
    end for
    return 1
end type

Alan
  =

new topic     » topic index » view message » categorize

2. Re: type string(sequence s)

I think that's the only way a string type can be created. However, if the speed
is your concern, it might be somewhat "tweakable"...

Replacing

   if not (s[i] >=0 and s[i] <= 255) then

with

   c = s[i]
   if (c < 0) or (c > 255) then

and having 'c' declared at the beginning of the type statement might yield a
slight speed increase, particularly with long strings.


   Rod Jackson

----------
From:   Alan Tu[SMTP:ATU5713 at COMPUSERVE.COM]
Sent:   Wednesday, March 10, 1999 5:02 PM
To:     EUPHORIA at LISTSERV.MUOHIO.EDU
Subject:        type string(sequence s)

Is there a better way to do this?

type string(sequence s)
    for i = 1 to length(s) do
        if not (s[i] >= 0 and s[i] <= 255) then
            return 0
        end if
    end for
    return 1
end type

Alan

new topic     » goto parent     » topic index » view message » categorize

3. Re: type string(sequence s)

--this should work:

type string(sequence s)
    if find(0, (s >= 0 and s <= 255)) then
        return 0
    else
        return 1
    end if
end type


--Mark / Liquid-Nitrogen.

new topic     » goto parent     » topic index » view message » categorize

4. Re: type string(sequence s)

You are allowing NON printable characters. You might look at

Normand M. Blais string.e in the archive.

new topic     » goto parent     » topic index » view message » categorize

5. Re: type string(sequence s)

On Wed, 10 Mar 1999, Liquid-Nitrogen Software wrote:

] type string(sequence s)
]     if find(0, (s >= 0 and s <= 255)) then
]         return 0
]     else
]         return 1
]     end if
] end type

Taking it one step further:

type string(sequence s)
    return 0 = find(0,s >= 0 and s <= 255)
end type
-- ">=", "<=", "and", "find" and "=" -- 5 calculations

But if s contains an atom it isn't spotted! So...

To infinity and beyond:

type string(sequence s)
    return 0=find(0,s=and_bits(s,255))
end type
-- "and_bits", "=", "find" and "=" -- 4 calculations = faster(untested)

However, for really long strings, the original "for" loop may be faster
because it stops at the first error rather than checking everything. EMWV.

HTH,
Carl

--
Carl R White -- Final Year Computer Science at the University of Bradford
E-mail........: cyrek- at -bigfoot.com -- Remove hyphens. Ta :)
URL...........: http://www.bigfoot.com/~cyrek/
Uncrackable...: "19.6A.23.38.52.73.45 25.31.1C 3C.53.44.39.58"

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu