Hi,
again I am strugling with strings. In this case: manipulating them.
In al the basic dialects that I know of, there were statements like:
dim a as string[10], dim b as string[10]
a="1234567890"
then I used:
b = left (a,4) 'resulting in b=1234
or,
if left(a,3)="123" then....
So basically I am looking for the statements: Left, Right, or Mid(string).
Now, I found in a list of keywords, the words left, mid and right, as reserved words.
However no explanation of how to use them.
Starting with B=right( , I get a pop up that says "no parameters expected".
Can you explane how this should be used ?
Rob
More string questions
Re: More string questions
Unbelievable, well over 2000 views in 3 days. 700/day and
not ONE reply ? Not even from the helpdesk ? Anyone ?
Simple question I think: Is there an instruction like
Mid(string ), Right(string) and left(string) ? If not, why not ?
How are the keywords mid, left and right in the manual used ?
regards,
Rob
not ONE reply ? Not even from the helpdesk ? Anyone ?
Simple question I think: Is there an instruction like
Mid(string ), Right(string) and left(string) ? If not, why not ?
How are the keywords mid, left and right in the manual used ?
regards,
Rob
- nadir.celebic
- mikroElektronika team
- Posts: 465
- Joined: 15 Jun 2016 13:19
Re: More string questions
Hi,
Unfortunately, Left, Right and Mid doesn't exist in our compilers, they are only reserved words, as with any other BASIC oriented language.
I write test program for Left and Right to show you how this work.
Middle works on the same principle.
Regards,
Nadir
Unfortunately, Left, Right and Mid doesn't exist in our compilers, they are only reserved words, as with any other BASIC oriented language.
I write test program for Left and Right to show you how this work.
Middle works on the same principle.
Code: Select all
program Test
dim txt_destination as string[16]
dim txt_source as string[16]
dim string_length as word
sub procedure right_(dim str as ^char, dim character_place as byte)
dim temp as byte volatile
string_length = strlen(str)
temp = string_length - character_place
memcpy(@txt_destination, @txt_source + temp, character_place)
end sub
main:
txt_source = "mikroElektronika"
' left
strncpy(txt_destination,txt_source,5)
' right
right_(@txt_source, 11)
asm nop end asm
end.
Nadir
Re: More string questions
Nadir, thanks for your reply.
I'am almost afraid to keep asking questions, but it still doesn't work as I expected.
I tried only the "left" example, because this example does not
need any self-written procedures, only the strncpy command.
To see the result, I send the result to the serial link.
The CRLF sends a CR+LF to the serial link. At least that works.
I used the following code:
txt_source = "mikroElektronika"
CRLF
UART1_Write_text(txt_source)
CRLF
strncpy(txt_destination,txt_source,6)
UART1_Write_text(txt_destination)
The result is:
mikroElektronika
mikroE456789
So basically it works: It prints the txt_source, a CR+LF
and the left 6 characters which are in txt_destination: mikroE
However, it also prints "456789", a left over from a previous test.
If I replace the 6, by a byte variable, the result is even more unbelievable:
So:
dim CC as byte
CC = 6
strncpy(txt_destination,txt_source,CC)
Result is:
mikroElektronika
mikroEektronika
as you see, somehow there is an "l" missing.
Both source and string vars are 16 bytes long, so that shouldn't be a problem.
What am I doing wrong this time ?
Hope to here from you soon. Regards,
Rob
I'am almost afraid to keep asking questions, but it still doesn't work as I expected.
I tried only the "left" example, because this example does not
need any self-written procedures, only the strncpy command.
To see the result, I send the result to the serial link.
The CRLF sends a CR+LF to the serial link. At least that works.
I used the following code:
txt_source = "mikroElektronika"
CRLF
UART1_Write_text(txt_source)
CRLF
strncpy(txt_destination,txt_source,6)
UART1_Write_text(txt_destination)
The result is:
mikroElektronika
mikroE456789
So basically it works: It prints the txt_source, a CR+LF
and the left 6 characters which are in txt_destination: mikroE
However, it also prints "456789", a left over from a previous test.
If I replace the 6, by a byte variable, the result is even more unbelievable:
So:
dim CC as byte
CC = 6
strncpy(txt_destination,txt_source,CC)
Result is:
mikroElektronika
mikroEektronika
as you see, somehow there is an "l" missing.
Both source and string vars are 16 bytes long, so that shouldn't be a problem.
What am I doing wrong this time ?
Hope to here from you soon. Regards,
Rob
- nadir.celebic
- mikroElektronika team
- Posts: 465
- Joined: 15 Jun 2016 13:19
Re: More string questions
Hi,
Can you please send me your project in .zip, so I could test it?
Regards,
Nadir
Can you please send me your project in .zip, so I could test it?
Regards,
Nadir
Re: More string questions
Nadir,
see the attachment. Despite the name ( test1), the file is located on D:\MBasic\Test0.
I hope you can tell me why things go wrong.
Regards,
Rob
see the attachment. Despite the name ( test1), the file is located on D:\MBasic\Test0.
I hope you can tell me why things go wrong.
Regards,
Rob
- Attachments
-
- Test0.zip
- (25.04 KiB) Downloaded 187 times
- nadir.celebic
- mikroElektronika team
- Posts: 465
- Joined: 15 Jun 2016 13:19
Re: More string questions
Hi,
There is some problem with UART.
I recommend to check our examples for UART, maybe will help.
Please check example in attachment.
Regards,
Nadir
There is some problem with UART.
I recommend to check our examples for UART, maybe will help.
Please check example in attachment.
Regards,
Nadir
- Attachments
-
- Uart.zip
- (35.05 KiB) Downloaded 169 times
Re: More string questions
Nadir,
I looked at the file you uploaded. It looks pretty much the same
as the files in the example directory, which I used as a template.
My test or your example makes no difference: they don't work.
What do you mean: "some problem with the UART" ?
I initialize to 9600 baud and I am able to send a direct string
(UART1_Write_text("String Test"). So the uart seems to work.
How can it be that the routine: strncpy(txt_destination,txt_source,5)
with the string variables in ext. memory does not work ?
That has nothing to do with the uart I think. Has it ?
Why does a routine like UART1_Write_text(string) only work when the
string is in internal memory and not when in external memory ?
Please explane what I am doing wrong or if this is a compiler error ?
Regards, Rob
I looked at the file you uploaded. It looks pretty much the same
as the files in the example directory, which I used as a template.
My test or your example makes no difference: they don't work.
What do you mean: "some problem with the UART" ?
I initialize to 9600 baud and I am able to send a direct string
(UART1_Write_text("String Test"). So the uart seems to work.
How can it be that the routine: strncpy(txt_destination,txt_source,5)
with the string variables in ext. memory does not work ?
That has nothing to do with the uart I think. Has it ?
Why does a routine like UART1_Write_text(string) only work when the
string is in internal memory and not when in external memory ?
Please explane what I am doing wrong or if this is a compiler error ?
Regards, Rob
- nadir.celebic
- mikroElektronika team
- Posts: 465
- Joined: 15 Jun 2016 13:19
Re: More string questions
Hi,
You are right, there is problem with those strings.
I will pass this to our developer team, then I will tell you more about this.
Regards,
Nadir.
You are right, there is problem with those strings.
I will pass this to our developer team, then I will tell you more about this.
Regards,
Nadir.
Re: More string questions
Nadir,
in that case you might want to ask them to implement the left, right and mid string statements as well ?
This could be done in... a few days or so ?
Regards,
Rob
in that case you might want to ask them to implement the left, right and mid string statements as well ?
This could be done in... a few days or so ?
Regards,
Rob
- nadir.celebic
- mikroElektronika team
- Posts: 465
- Joined: 15 Jun 2016 13:19
Re: More string questions
Hi,
Unfortunately, currently I can't tell you with certainty.
This is pass to our developer team.
Regards,
Nadir
Unfortunately, currently I can't tell you with certainty.
This is pass to our developer team.
Regards,
Nadir