Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 17:39 27 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Manipulating strings...

Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 04:25pm 10 Mar 2013
Copy link to clipboard 
Print this post

Hi all


I am just trying to work out how to manipulate some strings, and I am having a bit of trouble working it out.

If A$="000 abcdefghHE", how do I select specific bytes from this string, in order to reformat the string?

I want to reformat this to something along the lines of A$="00abcdef", so I am trying to work out how you read a specifc byte from inside a string.

I will keep searching the forums now, but so far, I have not found what I need.

Any pointers appreciated.




Smoke makes things work. When the smoke gets out, it stops!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 04:47pm 10 Mar 2013
Copy link to clipboard 
Print this post

You can read a specific character from a string with the MID$ function.
In basic you normally 'walk' through the characters one by one and collect or skip characters according your needs.

[code]
FOR Index = 1 to LEN(value$)
character$ = MID$(values$,Index,1)
'do your test and work here
NEXT
[/code]
I can not really workout your requirements with the sample you provided.
Maybe more samples worked out by hand, or a list of requirements can help writing a specific solution.
If you need characters from specific positions it will be easier.
You can then use the same MID$ function and supply the starting position and length of the part you want to extract.

Edited by TZAdvantage 2013-03-12
Microblocks. Build with logic.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 04:59pm 10 Mar 2013
Copy link to clipboard 
Print this post

Cheers TZA!!!!

Yes, every string I want to reformat, is always the same format, and always 14 bytes long.

So, using HEX to illustrate:

Received string will be: "0123456789ABCD"

I will ALWAYS want to reformt that into an 8-byte string in the format: "12456789"

Essentially, ignore the bytes "0", "3", "A" and "B" and save bytes "C" and "D" in seperate strings.

Now that I have a command(MID$) to work from, I will see what I can do.

Thanks again.Edited by Grogster 2013-03-12
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 06:35pm 10 Mar 2013
Copy link to clipboard 
Print this post

YAY!

All working.

The code is:

[code]
start:
A$="123#abcdefghM_" 'Sample string
FN$=Mid$(A$,2,2) + Mid$(A$,5,6) 'Build what I need
MDE$=Mid$(A$,13,1) 'MDE$ is the mode byte
EXT$=Mid$(A$,14,1) 'EXT$ is the extra function byte
[/code]

Edited by Grogster 2013-03-12
Smoke makes things work. When the smoke gets out, it stops!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 06:49pm 10 Mar 2013
Copy link to clipboard 
Print this post


Microblocks. Build with logic.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024