GLBasic forum

Main forum => Bug Reports => Topic started by: spicypixel on 2012-Sep-10

Title: String Concatenation Bug
Post by: spicypixel on 2012-Sep-10
This works
Code (glbasic) Select
tmp$ = OUTPUTDIR$ + regplate$ + files$[i] + "\n"

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

?????  :rant: ?????
Title: Re: String Concatenation Bug
Post by: spicypixel on 2012-Sep-10
Works
Code (glbasic) Select
regplate$ = regplate$ + "."

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

This is sooooo foolish ????
Title: Re: String Concatenation Bug
Post by: Minion on 2012-Sep-10
I think its due to the \ being part of a control sequence. if you use \\ it should insert a single \ into the string
Title: Re: String Concatenation Bug
Post by: spicypixel on 2012-Sep-10
Its still foolish though, I used CHR$(92) in the end.
Title: Re: String Concatenation Bug
Post by: 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.
Title: Re: String Concatenation Bug
Post by: Minion on 2012-Sep-10
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 ;)
Title: Re: String Concatenation Bug
Post by: MrTAToad on 2012-Sep-10
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...
Title: Re: String Concatenation Bug
Post by: spicypixel on 2012-Sep-10
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.
Title: Re: String Concatenation Bug
Post by: matchy on 2012-Sep-10
 <3
Title: Re: String Concatenation Bug
Post by: Moru on 2012-Sep-10
"\" 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 :-)
Title: String Concatenation Bug
Post by: spicypixel on 2012-Sep-10
What personal remarks
Title: Re: String Concatenation Bug
Post by: Minion on 2012-Sep-10
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.
Title: Re: String Concatenation Bug
Post by: Moru on 2012-Sep-10
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>"
Title: Re: String Concatenation Bug
Post by: matchy on 2012-Sep-10
Would it be more polite to ask not to be an error\n?
Title: Re: String Concatenation Bug
Post by: MrTAToad on 2012-Sep-10
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...
Title: Re: String Concatenation Bug
Post by: r0ber7 on 2012-Sep-10
\ is evil.
Title: Re: String Concatenation Bug
Post by: hardyx on 2012-Sep-11
Use allways "/" to separate paths, and the language converts for you to the target platform. Use "\" only for control characters, they are powerful, if you need to put a single \ put "\\" (control code for back slash).