Code: Select all
EnableExplicit
Procedure test(st.i)
Protected.String *s
*s = @st
*s\s = "foo" ;OK?
;PokeS(st, "foo") ;Wrong?
EndProcedure
Define.s st
st = ""
test(@st)
Debug st
Code: Select all
EnableExplicit
Procedure test(st.i)
Protected.String *s
*s = @st
*s\s = "foo" ;OK?
;PokeS(st, "foo") ;Wrong?
EndProcedure
Define.s st
st = ""
test(@st)
Debug st
Code: Select all
st = space(512)
Code: Select all
EnableExplicit
Procedure test(st.i)
Protected.String *s
*s = @st
*s\s = "Hello World"
Debug "Local: " + @*s\s
;PokeS(st, "foo") ;Wrong?
EndProcedure
Define.s st
st = "123"
Debug "Main: " + @st
test(@st)
Debug "Main: " + @st
Debug st
Code: Select all
Procedure test(*s.String)
*s\s = "Hello World"
EndProcedure
Define MyString.String
MyString\s = "123"
test(@MyString)
Debug MyString\s
Code: Select all
EnableExplicit
Prototype.i ReplaceChar(String$, cSearch.c, cReplace.c) ; ProtoType-Function for ReplaceChar
Global ReplaceChar.ReplaceChar ; define Prototype-Handler for CountChar
Procedure.i _ReplaceChar(*String, cSearch.c, cReplace.c)
Protected *char.Character ; Pointer to a virutal Char-Struct
Protected N
*char = *String
If *char
While *char\c ; until end of String
If *char\c = cSearch
*char\c = cReplace ; replace the Char
N + 1
EndIf
*char + SizeOf(Character) ; Index to next Char
Wend
EndIf
ProcedureReturn N
EndProcedure
ReplaceChar = @_ReplaceChar() ; Bind ProcedureAdress to the PrototypeHandler
Define Txt$="1234561.123456111"
Debug Txt$
ReplaceChar(Txt$, '1', 'A') ; Txt$ is passed as @Txt$
Debug Txt$
If you pass the pointer, then you must accept it as a pointer
Code: Select all
Procedure test(*st)
Code: Select all
Procedure test(*st.Integer)
Here, "st" is a pointer, and you again take the pointer from it. You don't have a string in the pointer, but a number pointer.
This part of Justin's code is right.AZJIO wrote: Tue Feb 25, 2025 2:49 pmHere, "st" is a pointer, and you again take the pointer from it. You don't have a string in the pointer, but a number pointer.
Code: Select all
Define String.s = "Hello World" ; The string
Define *Pointer = @String ; Pointer to the String content itself
Define *StringStructure.String = @*Pointer ; Pointer to the String-Pointer
Debug *StringStructure\s
Code: Select all
Procedure.s TrimLeft(*a, n)
Protected *p.string = @*a
*p\s = Right(*p\s, Len(*p\s) - n)
EndProcedure
tmp$ = "Hello world"
TrimLeft(@tmp$, 3)
Debug tmp$
Code: Select all
Define st.String
test(@st)
Exactly.AZJIO wrote: Tue Feb 25, 2025 3:56 pm If you are passing a pointer instead of a structure, then you cannot increase the length of the string, since it is declared in the outer scope.