View previous topic :: View next topic |
Author |
Message |
Tiny
Joined: 10 Nov 2010 Posts: 110 Location: The Netherlands

|
Posted: Mon Mar 02, 2020 4:53 pm Post subject: adding a null to a string |
|
|
Hello,
Is there as possibility the add manually a "null" to a string
for example
Code: |
$regfile = "m88pdef.dat"
$crystal = 4000000
$hwstack=40
$swstack=16
$framesize = 32
Dim Mystring As String * 40
Dim Aa As Byte
For Aa = 1 To 10 'fill the string with 10 chars
Mid(mystring , Aa , 1) = "a"
Next Teller
Print Len(mystring)
'result = 10
For Aa = 1 To 4 'fill the string with 4 chars
Mid(mystring , Aa , 1) = "b"
Next Teller
Print Len(mystring)
'result = 10
'after the fourth "b" there must be a "null"to terminate the string
End
|
regards Tiny
(BASCOM-AVR version : 2.0.8.2 ) |
|
Back to top |
|
 |
MWS
Joined: 22 Aug 2009 Posts: 2335

|
Posted: Mon Mar 02, 2020 7:05 pm Post subject: |
|
|
Your code won't compile.
Beside this, overlay mystring with a byte-array and assign the 0 there. |
|
Back to top |
|
 |
Tiny
Joined: 10 Nov 2010 Posts: 110 Location: The Netherlands

|
Posted: Mon Mar 02, 2020 10:27 pm Post subject: |
|
|
Sorry for the wrong sample code
Your solution for using an array as overlay works, Thanks
Code: |
$regfile = "m88pdef.dat"
$crystal = 4000000
$hwstack=40
$swstack = 16
$framesize = 32
Dim Mystring As String * 40
Dim Bytes(40) As Byte At Mystring Overlay
Dim Aa As Byte
For Aa = 1 To 10 'fill the string with 10 chars
Mid(mystring , Aa , 1) = "a"
Next Aa
Print Len(mystring)
'result = 10
For Aa = 1 To 4 'fill the string with 4 chars
Mid(mystring , Aa , 1) = "b"
Next Aa
Bytes(5) = 0
Print Len(mystring)
'result = 10
'after the fourth "b" there must be a "null"to terminate the string
End
|
|
|
Back to top |
|
 |
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland

|
Posted: Tue Mar 03, 2020 2:28 am Post subject: |
|
|
Quote: |
For Aa = 1 To 4 'fill the string with 4 chars
Mid(mystring , Aa , 1) = "b"
Next Aa
Bytes(5) = 0
|
You can also do it without the overlay:
Code: |
For Aa = 1 To 4 'fill the string with 4 chars
Mid(mystring , Aa , 1) = "b"
Next Aa
' then:
Mid(mystring,5,1) = 0
'note this is NOT the same as:
Mid(mystring,5,1) = "0"
|
Certainly the overlay works, and for some things, its a very elegant solution, but it is a bit obscure. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
 |
EDC
Joined: 26 Mar 2014 Posts: 1135

|
Posted: Tue Mar 03, 2020 9:20 am Post subject: |
|
|
For "same characters strings" you can use String function instead, nonefficient here, For-Next loop.
Code: | Dim Mystring As String * 40
Mystring = String(10 , 97) '10x "a"
Print Mystring
Mystring = String(4 , 98) '4x "b"
Print Mystring
End |
|
|
Back to top |
|
 |
Tiny
Joined: 10 Nov 2010 Posts: 110 Location: The Netherlands

|
Posted: Wed Mar 04, 2020 7:46 am Post subject: |
|
|
Hey,
thanks everyone for the solutions provided.
Regards Tiny |
|
Back to top |
|
 |
|