PerfectScript Journal
 

May 1997 Macro Q&A

Stripping spaces from the ends of a string

Q. How can I strip any extra spaces from the beginning and ending of a string of text?

A. In WPWin 7, the STRTRIM command can be used to strip extra spaces from the ends of a string of text.

vNewString:=StrTrim(vString; ; TrimEnds!)         

In WPWin 6.1, it takes a bit more work.

Repeat
        If(StrPos(vString; " ")=1)
                vString:=SubStr(vString; 2)
        Endif
Until (SubStr(vString;1;1)<>" ")
vLength:=StrLen(vString)
Repeat
        If(SubStr(vString; vLength; 1)=" ")
                vString:=SubStr(vString; 1; vLength-1)
                vLength:=vLength-1
        Endif
Until (SubStr(vString;vLength;1)<>" ")           

Counting lines of macro code

Q. I often get compiler errors that refer me to a specific line in the macro. How can I get to the error quickly?

A. There are three ways to get to a specific error point in a macro.

1. When you get the compiler error, click the Cancel Compilation button. The insertion point will be placed at or near where the error was encountered.

2. Use a macro called LINENUM.WCM that ships with WordPerfect. This macro allows you to specify the line number and character number to go to, then places the insertion point at that location in your macro code.

3. Turn on the Line Numbering Feature. Click Format | Line | Numbering, then select the check box to turn line numbering on. Make sure you also unselect the check box to restart numbering at the top of each page.

Also, keep in mind that a macro line is considered the space from one hard return to the next, so if you have a long macro command that requires two or more lines, it is istill considered only one line.

 

Copyright Notice: The information included in the PerfectScript Journal is protected by US Copyright. The author grants you the right to use the routines in your own macros as needed. You may not sell, distribute, or publish them in any form.
If you choose to use the information here, you do so entirely at your own risk. No representations are made regarding the fitness of this information for your   particular purpose, or for your ability or inability to use the information. You   are advised to make backups of all relevant files before implementing any suggestion  or technique.
© Copyright 1997 by J. Jeppson.