GLBasic forum

Main forum => Bug Reports => Topic started by: uwe_gl on 2018-Aug-18

Title: Funktion gibt String - Variable mit "\" nicht zurück, aus \\ wird \
Post by: uwe_gl on 2018-Aug-18
Hallo,
Eine Funktion zum ersetzen der "\" mit "/" (zum Dateinamenumwandeln für SHELLCMD) gibt keinen Wert zurück wenn der String Sonderzeichen wie "\" oder "/" enthält. Es wird auch nur ein "\" in der Funktion umgewandelt, das 2. verschwindet ....

Code (glbasic) Select

GLOBAL a$="Test\\//Test"
PRINT a$,10,30
PRINT KONV(a$),10,100
SHOWSCREEN
MOUSEWAIT

END


// ------------------------------------------------------------- //
// ---  KONV  ---
// ------------------------------------------------------------- //
FUNCTION KONV: wert1$
// Diese Variablen sind als LOCAL definiert:
// wert1$
LOCAL wert2$

FOR t=0 TO LEN(wert1$)-1
IF MID$(wert1$,t,1)="/"
wert2$=wert2$+CHR$(92)
ELSE
wert2$=wert2$+MID$(wert1$,t,1)
ENDIF
NEXT
PRINT wert2$,10,50
RETURN wert2$
ENDFUNCTION // KONV

Title: Re: Funktion gibt String - Variable mit "\" nicht zurück, aus \\ wird \
Post by: Qedo on 2018-Aug-18
Change KONV in KONV$ (2 places).
The second \ disappears because \ is a special character and works in tandem with the next
Title: Re: Funktion gibt String - Variable mit "\" nicht zurück, aus \\ wird \
Post by: dreamerman on 2018-Aug-18
I will just add a little to above response from Qedo.
In GlBasic there are 3 types of variables: # - floating point (default), % - integer, $ - string. You should always use those chars in declaration of vars and also functions, so in this code use KONV$ instead of KONV (that would return floating point value).
Second issue: GLB converts code to C++ sources, that are later compiled by GCC, in C++ (and other languages) the '\' is an escape character for special commands like regex expressions, and compiler tries to handle '\\' as such special command. It only aplies to statically typed string's so it wont appear in string from Input, grabbed from files, made with Chr$() and so on.
To avoid this just use:
GLOBAL a$="Test" + CHR$(92) + CHR$(92) + "//Test"
Title: Re: Funktion gibt String - Variable mit "\" nicht zurück, aus \\ wird \
Post by: uwe_gl on 2018-Sep-02
Thanks,
with this help i chnage the code. It works now for me.
:)