[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Any easy way to change a string ? and a bug (or maybe a feature ?)
[Thread Prev] | [Thread Next]
- Subject: Re: Any easy way to change a string ? and a bug (or maybe a feature ?)
- From: Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>
- Date: Mon, 14 Oct 2024 20:17:29 +0200
- To: user@xxxxxxxxxxxxxxxxxxxxxx
Le 14/10/2024 à 19:06, Brian G a écrit :
-- I am pretty sure Ben would not like this but....
You are right. I hardly could imagine something more horrible. :-)
When I am using a string as a buffer I use the following function to modify it and resend it, It works with &hff as well_________________ ' Gambas module fileExtern memcpy(src As String, dest As String, len As Integer) As Pointer In "libc:6"'' Position is 0 relative not 1, value may be numeric or a single character stringPublic Sub setChar(var As String, value As Variant, position As Integer) Dim myValue As Byte Dim myPtr As Pointer If position < 0 Or position >= var.len Then Error.Raise(("Specified position out of bounds")) Endif If TypeOf(value) = gb.string Then myValue = CByte(Asc(value[0])) Else myValue = CByte(value) Endif myPtr = memcpy(var, var, 0) Byte@(myPtr + position) = myValue End Public Sub Main() Dim a As String = "hello world" Print a setChar(a, "g", 1) Print a setChar(a, &hff, 4) Print a End --------------- Output is hello world hgllo world hgll? world --------------- end output I hope this helps and not confuses... works for me as needed ~~~~ Brian
Strings are immutable. If you modify them by circumventing the interpreter, it can lead to any crash at any moment.
If you need a byte buffer as as string, use OPEN STRING or Byte[]. Regards, -- Benoît Minisini.
Re: Any easy way to change a string ? and a bug (or maybe a feature ?) | Brian G <brian@xxxxxxxxxxxxxxxx> |
Re: Any easy way to change a string ? and a bug (or maybe a feature ?) | Brian G <brian@xxxxxxxxxxxxxxxx> |
Any easy way to change a string ? and a bug (or maybe a feature ?) | Laurent Carlier <lordheavym@xxxxxxxxx> |
Re: Any easy way to change a string ? and a bug (or maybe a feature ?) | Brian G <brian@xxxxxxxxxxxxxxxx> |