Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removing unwanted spaces from a string 2

Status
Not open for further replies.

rcr22b

Vendor
Apr 27, 2011
3
US
This may be simple problem for some of you but it has me stumped:

CLS
ctr = 1
ctr$ = STR$(ctr)
a$ = a$ + "000" + ctr$
PRINT a$
END

What I get is 214275000 1.

What I want is 2142750001

How can I remove the space from this string?
 
Let me explain my problem more.

I don't care what is printed on the screen.

I am comparing two strings from different sources.

One string is from a file and does not contain a space.

The other sting is generated by my code and I need to remove the space from that string.

Thanks.
 
I am not sure if these functions exist in the language you are using, however, you could try:

Code:
ctr$ = trim$(str$(ctr))
'Trim removes any leading or trailing spaces.

If you have number, space(s) and more numbers, you can use a function similar to:

Code:
Replace$(ctr$, " ", "")
'Replace any space in the string with nothing, thus it removes all spaces.

If at first you don't succeed, then sky diving wasn't meant for you!
 
Thanks to everyone for the help.

I knew there had to be a way.
 
>Ctr$= FORMAT(ctr$,"###########")

That won't work correctly if the digit after the space is a 0 (and there's nothing in the OP to suggest that it might not be).

Mind you, reviewing the original code suggests the whole problem can be avoided by using one of two different conversion techniques:

Change [tt]ctr$ = STR$(ctr[/tt]) to [tt]ctr$ = CStr$(ctr)[/tt]

or delete [tt]ctr$ = STR$(ctr)[/tt] and change [tt]a$ = a$ + "000" + ctr$[/tt] to [tt]a$ = a$ + "000" + ctr[/tt] (or, perhaps better, [tt]a$ = a$ & "000" & ctr[/tt])


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top