Is the following the correct way to write a string to hard drive to include commas in the string'
I did not see an example in the manual. What about other special characters . Are there any other special rules.
OPENCONSOLE
DEF myfile:FILE
IF(OPENFILE(myfile,"C:\CBASICTEST.TXT","W") = 0)
WRITE myfile,"john Henry, Philip Hughes"
CLOSEFILE myfile
PRINT "File created successfully"
ELSE
PRINT "File could not be created"
ENDIF
PRINT "Press Any Key To Close"
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE
END
Thanks
Texas Pete
The only specialthings I can think of right now is if you wanted to have \ or " in your string.
LarryMc
Larry would I put the slash or quote In quotes or use a chr$ code like
write , using say a chr$(34) for quote.
WRITE myfile,chr$(34)+"john Henry, Philip Hughes"+chr$(34)
Texas Pete
Thanks
I don't thick CBasic recognizes escape sequences so you would have to use Chr$() like you've done.
In IWB for a \ and a " you would use \\ and \"
LarryMc
I don't see the problem. This example prints to the screen, but writing to a file would be just the same.
openconsole
cls
a$="This is a $2 test, isn't it? - I thought so!"
print a$
a$ = "She said "Hello" - and I smiled."
print a$
do:until inkey$<>""
closeconsole
end
best wishes, :)
Graham
Graham ,
The reason I was asking is because several other basics that I have used in the past had special ways to handle a comma. In the old commodore several hidden characters simple could not be written to hard drive with out substituting one character code for another and then swapping the character back upon reading a string back in. So far the more up to date languages, each had unique requirements.
I am simply trying to understand how the writer of the compiler expected it to be handled
Thanks
Texas Pete
@Graham
While there is no problem with this
a$ = "She said "Hello" - and I smiled."
print a$
This won't print
a$ = "She said "Why, Hello!" - and I smiled."
print a$
LarryMc
Hi Larry, :)
It works fine for me - but then I'm still using CB Version 1.0.
Some problems seem to have been introduced into later versions, which I don't use because none of the recent changes brought anything I really needed.
best wishes, :)
Graham