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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Spaces from integers 1

Status
Not open for further replies.

Stainnd

Programmer
Jul 9, 2001
65
0
0
US
Very simple problem. I save an integer. I call it. I print it. It prints as " integer ". In other words, it prints with a space on either side of the integer. How can I stop this and why does it happen? Thanks -Mike
 
I think the easiest thing to do would be to convert the integer to a string using STR$ and then print that. This will eliminate the spaces.
 
for saving Integers it is much cleaner to open the file in BINARY mode and use PUT to store the data, which just lumps the data unformatted into the file and expects you to know the byte length of the individual pieces of data you store and read them in correctly. WRITE formats the file for you that's why you get spaces.

If you need an example..

Open FileName$ For BINARY as #1

PUT #1,,MyInteger

Close


To retrieve the data,

Open FileName$ For BINARY as #1

GET #1,,MyInteger


You just need to design your getting and putting so you can retrieve the data without much confusion....


 
No, i don't even mean getting and putting. I mean i write numcards = 5 for instance and Print numcards write 5 with a space on either side. -Mike
 
No, i don't even mean getting and putting. I mean i write numcards = 5 for instance and Print numcards writes 5 with a space on either side. -Mike
 
Use what I said earlier STR$. To add to it, now even if they still appear there, use LTRIM$ and RTRIM$.
 
CLS
input "enter a number and press enter: ", MyNumb
print
print "The unsigned integer is:"; MyNumb
MyNumb= MyNumb * -1
print "the signed integer is:"; MyNumb
print
Squish$=ltrim$(str$(MyNumb))
print "The integer with no space:"; Squish$
print
end

I'm not sure what you are talking about but does the above help? --MiggyD

Never be afraid to try something new. Remember that amateurs built the Ark. Professionals built the Titanic.
 
The problem is that [tt]PRINT[/tt] automatically pads numeric values that it outputs. It puts an extra space after them, and it puts a space before them when they are positive (when they are negative, it puts the '-' in that space, so you can't just discard the first character). The solution is to convert it to a string, but you don't need to use a variable in the process. Consider the following example:
[tt]
x% = 5
PRINT "x"; LTRIM$(STR$(x%)); "x"
[/tt]
It should output "x5x", without any spaces.
 
Thanks logiclrd. Your knowledge once again amazes me. You know, I never realized that you could use Print argument;argument;argument...i thought that you had to use a seperate print statement each time. Talk about a time saver. -Mike
 
Had you used the little program I wrote, you would have seen both "PRINT ;" and "LTRIM$" to guide you as well.

Glad you resolved your problem though. --MiggyD

Never be afraid to try something new. Remember that amateurs built the Ark. Professionals built the Titanic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top