[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: Brian G <brian@xxxxxxxxxxxxxxxx>
- Date: Mon, 14 Oct 2024 10:06:25 -0700
- To: user@xxxxxxxxxxxxxxxxxxxxxx
On 10/14/24 08:19, Laurent Carlier wrote:
For example: DIM myString as String ="RETUIOPLJBDNLQSXNKNSXKSXKBSKXKBBB" I would like to change the 10th character, replacing it with another. I can't find an easy way to do it. Is it a bug ?: DIM myByte as Byte = &hFF& DIM myString as String = "test string :" myString &= CStr(myByte) gives "test string :0\x00FF" instead of "test string :0\xFF", Byte is converted to a Short value, so unusual. As a workaround, i use chr$(myByte) Regards, Laurent Carlier
--
I am pretty sure Ben would not like this but....
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 file
Extern 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 string
Public 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
Attachment:
OpenPGP_0x78BFB26402F48419.asc
Description: OpenPGP public key
Attachment:
OpenPGP_signature.asc
Description: OpenPGP digital signature
| Re: Any easy way to change a string ? and a bug (or maybe a feature ?) | Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx> |
| Any easy way to change a string ? and a bug (or maybe a feature ?) | Laurent Carlier <lordheavym@xxxxxxxxx> |