CW strings (was CW1501 strings) 
Author Message
 CW strings (was CW1501 strings)

James,

The strings in CW work fine, but only after you understand a few
essential CW quirks.  Below are the concepts that caused me the most
trouble; I'm sure others can add to the list.

I can't help you with the literal problem.

Rules for working with strings.

1.  If in *any* doubt, use CLIP.  (also review LEFT and RIGHT functions)

        e.g.   str1 = CLIP(Str2)
    ALWAYS use clip on the first string in concatenations:
        e.g.   str1 = CLIP(Str2) & ' * ' & str3

2.  You cannot (or more accurately, I've never been able to ...) assign
        a string to itself:

        e.g.  NOT VALID(?) ->  str1 = CLIP(str1) & str2

        VALID:  CLEAR(str3)
                str3 = CLIP(str1) & str2
                str1 = str3
                CLEAR(str3)

        (BTW, the statement str1 = str1 & str2 will NEVER work, because
even if str1 has only a few characters in it, CW will carry and assign
all the blank characters in str1, leaving no space for str2)

3.  String slicing is an effective means for subsetting strings (see
also SUB function).

        if:  str1 = 'Comment 1:   This is the string."
                assign comment to string 2:
                position# = instring(':', str1)
                len# = length(str1)
                str2 = LEFT(str1[position#+1:len#])

        yields str2 -> "This is the string"

Your frustrations sound very familiar -- CW will handle strings quite
effectively, but there are a few pitfalls.

good luck!
johng

Quote:

>    I have tried using STRING variables with little to no satisfaction
> given the fact that I do alot of string concatenations in my programs.
> The statement        s = s & '*' & fld         just didn't seem to
> work.  So I have gone CSTRING as my choice, as it appears to
> initialize the strings to 0 length, and I assume reserving the space
> for the full length specified in the declaration,  where I was not
> able to change the length in the STRING type dynamically at all.
> I am currently exaggerating the string lengths (250) as I work with
> wildly variable length data.  Usually only a couple dozen characters
> are enough but there are occasions where the data could be as long as
> 200+ characters in length.

> Are there any completely variable length string types in CW?

> Also, I can't seem to pass a literal to my hand coded functions.

>   result = Tally(s, '*')  ! will not work

>   x = '*'
>   result = Tally(s, x) ! will work fine????

> Only STRING types can be passed to functions or at least only
> prototyped as STRING.  What am I doing wrong in the example shown
> above?

> Thanks

> James Curry

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
John E. Gross
Natural Resource Ecology Laboratory
Ft. Collins, Colorado  USA  80532-1499

(970) 491-1796
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Fri, 15 Jan 1999 03:00:00 GMT  
 CW strings (was CW1501 strings)

Fred,

You are correct.  I must have messed something up when I originally tried this.  
Looks like I'll have to go back and delete all those extra lines of code I've been
using for months!

johng

Quote:

> > 1.  If in *any* doubt, use CLIP.
> > (also review LEFT and RIGHT functions)
> I prefer to use CSTRING then,  which eliminates the need for Clip() all
> the time.
> > 2.  You cannot (or more accurately, I've never been able to ..)
> >  assign a string to itself:

> >  e.g.  NOT VALID(?) ->  str1 = CLIP(str1) & str2
> I tried this,  and it works even if str1 is declared as a common STRING
> (ie not a CSTRING).  What's the problem?

> Fred Trter

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
John E. Gross
Natural Resource Ecology Laboratory
Ft. Collins, Colorado  USA  80532-1499

(970) 491-1796
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Sat, 16 Jan 1999 03:00:00 GMT  
 CW strings (was CW1501 strings)

Quote:
> 1.  If in *any* doubt, use CLIP.  
> (also review LEFT and RIGHT functions)

I prefer to use CSTRING then,  which eliminates the need for Clip() all
the time.

Quote:
> 2.  You cannot (or more accurately, I've never been able to ..)
>  assign a string to itself:

>  e.g.  NOT VALID(?) ->  str1 = CLIP(str1) & str2

I tried this,  and it works even if str1 is declared as a common STRING
(ie not a CSTRING).  What's the problem?

Fred Trter



Sat, 16 Jan 1999 03:00:00 GMT  
 CW strings (was CW1501 strings)


Quote:
>2.  You cannot (or more accurately, I've never been able to ...) assign
>    a string to itself:
>    e.g.  NOT VALID(?) ->  str1 = CLIP(str1) & str2

This is perfectly valid, I use it all the time.

Best Regards,

Andy Kaczmarczyk
Auratek International



Sun, 17 Jan 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. CW1501 Strings

2. Ada String Issue: String within Strings

3. string = string(i:j) // string(k:n)

4. I am trying to copy a text string from a front panel indicator to a text

5. I am trying to copy a text string from a front panel indicator to a text

6. string random generator (Sorry if too stupid, but i am a beginner)

7. CW 2.003 Search Strings

8. Bugs in CW 2.003 with Strings!

9. CW 2.0 Concatenation of Strings PROBLEM

10. Variable strings in CW and dynamic listbox

11. BUG: Scientific Number to String/String to Number

12. Picture to String/String to Picture

 

 
Powered by phpBB® Forum Software