String Concatenation Bug

Previous topic - Next topic

spicypixel

This works
Code (glbasic) Select
tmp$ = OUTPUTDIR$ + regplate$ + files$[i] + "\n"

This doesn't
Code (glbasic) Select
tmp$ = OUTPUTDIR$ + regplate$ + "\" + files$[i] + "\n"

?????  :rant: ?????
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

spicypixel

Works
Code (glbasic) Select
regplate$ = regplate$ + "."

Doesn't Work
Code (glbasic) Select
regplate$ = regplate$ + "\"

This is sooooo foolish ????
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Minion

I think its due to the \ being part of a control sequence. if you use \\ it should insert a single \ into the string

spicypixel

Its still foolish though, I used CHR$(92) in the end.
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Moru

#4
Why foolish? This is the way in many programming languages.

\ = start of escape sequence.
\n means new line
\r means carriage return.
\\ is replaced with a single \

I would miss this function badly if it didn't exist. Having to type CHR$(10) + CHR$(13) instead of "\r\n" to print a new line to the console for example.

The foolish part is windows using \ as a path separator. :-) I believe you should be using / in GLBasic, no matter what you are programming for.

Minion

Quote from: Moru on 2012-Sep-10

The foolish part is windows using \ as a path separator. :-) I believe you should be using / in GLBasic, no matter what you are programming for.

Yup ...found that part out too when trying cross platform stuff. I couldn`t work out why my some of my sounds wouldnt load on other devices... Was me being an idiot and using \ instead of / ! took me a week to find that after trying to resample all my sounds at different bitrates and formats. I dont make that mistake now tho ;)

MrTAToad

If you are using "\" as a path separator, you should use "/" instead.

Whilst it would be nice if the compiler automatically made sure that "\\" was used, it would cause problems inline as you might need to use "\" with escape codes...

spicypixel

Quote from: Moru on 2012-Sep-10
Why foolish? This is the way in many programming languages.

\ = start of escape sequence.
\n means new line
\r means carriage return.
\\ is replaced with a single \

I would miss this function badly if it didn't exist. Having to type CHR$(10) + CHR$(13) instead of "\r\n" to print a new line to the console for example.

The foolish part is windows using \ as a path separator. :-) I believe you should be using / in GLBasic, no matter what you are programming for.

It's foolish because when the language is being parsed prior to compiling, the fact that I get a syntax error because I'm joining a string which is defined as a STRING hence the quotes "\" should not give errors. It should know that its a string and not give an error, how can that NOT be foolish. I love GLB but don't be so rose tinted, this is a stupid error.
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

matchy

#8
 <3

Moru

"\" isn't a string. That's why you get errors.

It's like typing:

Code (glbasic) Select
a$ = "string here but no end string symbol.

because the \ uses the next character as a control character. Compiler does not know what you want.

I will just ignore your personal remarks since this is such a nice community :-)

spicypixel

What personal remarks
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Minion

Quote from: spicypixel on 2012-Sep-10

It's foolish because when the language is being parsed prior to compiling, the fact that I get a syntax error because I'm joining a string which is defined as a STRING hence the quotes "\" should not give errors. It should know that its a string and not give an error, how can that NOT be foolish. I love GLB but don't be so rose tinted, this is a stupid error.

\" is a control sequence to print a single quote so the compiler is expecting another quote on the end of your string thus "\"". its not an error.

Moru

This is very handy if you are outputting HTML-code since this includes a lot of " around attributes.
Eg:
Code (glbasic) Select
a$ = "<a href=\"www.glbasic.com\">GLBasic</a>"
// Instead of:
a$ = "<a href="+chr$(92)+"www.glbasic.com"+chr$(92)+">GLBasic</a>"

matchy

Would it be more polite to ask not to be an error\n?

MrTAToad

Being BASIC "\" should be treated as "\\" - but it would know when it is being used : Inline or standard for example.

Whether or not it would be easy to implement is another thing.   Perhaps a more descriptive error message is needed instead...