Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove Spaces From String Sub
#1
This isn't a request for code... actually I'm going to give it to you! The sub gets the new spaceless string as well as the number of spaces that were in the original string. Perhaps someone will have a use for it...

Code:
' Just a small sub to remove spaces for an input string
' 07-28-2003, AGs
' Use as you like :D

DECLARE SUB SpcRemover ()

SCREEN 13

CALL SpcRemover



SUB SpcRemover

  INPUT "Enter string : ", UserString$
  'db Print UserString$

  StringLen = LEN(UserString$)
  'db PRINT StringLen

  FOR x = 1 TO StringLen
    IF MID$(UserString$, x, 1) = " " THEN
      SpaceCount = SpaceCount + 1
    ELSE
      CleanString$ = CleanString$ + MID$(UserString$, x, 1)
    END IF
  NEXT x
  'db PRINT SpaceCount
  'db PRINT CleanString$

END SUB

I realize I could've just written it as part of the main module for the program but I wanted to be able to move it a bit more easily. As for the 'db those are just my debug checkpoints so instead of manually debugging it, I get to watch the values on screen while it does the work. I also have a function that I wrote in C++ for this as well if anybody is interested in getting it PM me.

Oh! Check out www.arcticgeckostudios.com we're still looking for more members Big Grin
Reply
#2
Code:
FUNCTION spaceless$ (text$)
  DO
    IF x > 0 THEN result$ = result$ + MID$(text$, y, x - y)
    y = x + 1: x = INSTR(y, text$, " ")
  LOOP UNTIL x = 0
  spaceless$ = result$
END FUNCTION

print spaceless$ ("Oh, I wish I was in Dixie, hurray! hurray!")

if you can copy it in chunks, copy it in chunks. But yous got the general idea. Nice work.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#3
Nice, I had refrained from doing a function because in Basic I don't quite understand them... or I guess I just haven't taken a hard enough look. C++ is fine, but Basic functions really mess with me... lol Thanks for posting!
Reply
#4
QB functions are easy enough. instead of using a return() statement, you just fill a variable named after the function:

function add% (x, y)
. . add% = x + y
end function

and the type of value returned is the type of variable the function name is:

function add% returns an integer
function add$ returns a string
function add! returns a single precision value.
function add# returns a double precision value.

...and you get the idea.

More information
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#5
Cool! Thanks... it makes a bit more sense now... it's just the syntax that was throwing me off, because I was expecting to return at the end instead.
Reply
#6
Toonski: Nice function name!! "Spaceless!!!"
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#7
*STABS* C++ and runs!
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#8
Code:
FUNCTION remspace$ (spc$)
FOR i = 1 TO LEN(spc$)
IF MID$(spc$, i, 1) <> " " THEN nspc$ = nspc$ + MID$(spc$, i, 1)
NEXT i
remspace$ = nspc$
END FUNCTION

PRINT remspace$("Go for food")

This is shorter
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)