Announcement

Collapse
No announcement yet.

Example of an added Built-In Function making a difference

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Frank Ferrell
    replied
    Greetings --

    A huge thanks to Kurt, a PowerBASIC member, for giving me a great tip on making the character-stripping routine in example-B (above post) MUCH simpler. Here's a copy of the e-mail he sent me.

    Code:
    Hi, Frank -
    
    I've been reading your messages in the PB forum.
    
    Regarding the "REMOVE$" function in PB4DOS, you can make your
    examples even simpler.
    
    You don't need the FOR/NEXT loop to cycle through the SELECT/CASE
    block.  All you are doing is string manipulation, so use the
    string manipulation tools.
    
    Start by defining a string of what you want to allow:
    
    LegalCharacters$ = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    
    Fetch the input:
    
    LINE INPUT, StringInQuestion$
    
    Force it to upper case:
    
    StringInQuestion$ = UCASE(StringInQuestion$)
    
    Take everything that's legal out of the string under test:
    
    Temp$ = REMOVE$(StringInQuestion$, ANY LegalCharacters$)
    
    If there is anything left in the temporary string it is illegal
    stuff,  and THAT's what you need to REMOVE$ from your
    StringInQuestion$:
    
    ProcessedString$ = REMOVE$(StringInQuestion$, ANY Temp$)
    
    This should also (by default) handle the situation where no
    'illegal' characters were put into Temp$ (because none existed in
    the StringInQuestion$), so you don't need an IF THEN/ELSE/END IF
    block that tests for LEN(Temp$) > 0.  In other words, the line
    above should also work as desired if LEN(Temp$) = 0.
    
    The end result of this module is something in the variable
    "ProcessedString$"
    
    Note that you could define non-alpha-cum-non-numeric characters
    in your LegalCharacters$ if you so desire. If you wanted to allow
    the double-quote mark, for example, you could append ' + CHR$(34)'
    to the line defining the allowable stuff; other printing
    characters could just be typed in with the rest of the literal
    string; non-printing characters need to be specified by
    concatenating their appropriate CHR$() values to the literal
    string.
    
    Kurt
    ------------------
    Thanx-A-Lot and Enjoy, Frank -- My PB

    [This message has been edited by Frank Ferrell (edited June 21, 2003).]

    Leave a comment:


  • Example of an added Built-In Function making a difference

    UPDATE: 6-18-2003 -- Examples Improved. Acknowledgement follows in next post

    Greetings --

    When I went from MS-Qbasic to PowerBASIC DOS, I - like many a programmer before and after - was introduced to many new features and improvements.

    One of those improvements was a built-in PowerBASIC function called REMOVE$. This one strips out any specified character from a given string.

    For example, if a string called HX$ contains this "R o-bocop7", and you wanted to take out the space as well as the "-" and the "7", then you would have this line ..
    HX$=Remove$(HX$, ANY "-7 ") which produces the result "Robocop"

    Suppose you wanted to remove a character that normally couldn't be shown in the ANY part of the Remove$ function - say the quote " mark. Easy - you would have this line--
    HX$=Remove$(HX$, any chr$(34))

    -- and similar lines for other such characters.

    ------------------
    Thanx-A-Lot and Enjoy, Frank --My PB


    [This message has been edited by Frank Ferrell (edited September 10, 2004).]
Working...
X