LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert a string to an array of character

I think I have an answer on speed issues. Martin's verion uses the String to Byte Array and Byte Array to String. These functions must go through every element of the array and do a conversion. Since there are two functions used, each element in the array must be accessed twice. Altenbach's version uses String to Byte Array, meaning each element is accessed once before the loop, then again when the loop is encountered. Again, each element is accessed twice. Shoneill's version accesss the elements once during the loop, and that is it. In my opinion, Shoneill's version should be faster, although Altenbach's version looks easier. Since Altenbach's version is the slowest by far, I would guess that the type cast function is not very fast.
- tbob

Inventor of the WORM Global
0 Kudos
Message 11 of 23
(1,759 Views)
Since I don't have very long string to convert, I'll opt for Altenbach's version, just because it involves less steps.
Thank you for your tests Shane.

Martin
0 Kudos
Message 12 of 23
(1,759 Views)
Martin,

For anything short, I would probably use my version too. 😉

Arrays of strings a just not the greatest way to shuffle things around in the code (remember, strings are stored as pointer to a structure that contains a 4 byte length value followed by an 1D array of byte integers, see application note 154). So each 1 character strings in your array occupies many bytes of rather useless information in this case (e.g. the completely redundant information that each element is length=1). 😞

IF you need to do computations on strings one character at a time, it is much better to keep everything at U8. You can do all the same things that you would do with "lenght=1 strings", but everything will be much more efficient. I don't know the purpose of your code, but that's something to keep in mind. 🙂
0 Kudos
Message 13 of 23
(1,744 Views)

Hi

 

I need exactly whats been discussed here. but i am unable to download any of the attachments. Can someone help please

 

Thanks

sarkar

0 Kudos
Message 14 of 23
(1,500 Views)
0 Kudos
Message 15 of 23
(1,492 Views)

Why do you need an array of individual characters? Typically who think they need that are actually needing something else.

 

Mike...

 

PS: You did notice of course that you appended your question to the end of a 6-year-old thread. That is not a way to be noticed. You are very lucky that you are getting any responses.


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 16 of 23
(1,485 Views)

Thanks for your reply. Didn't want to populate the forum with repeated questions. 

I actually wanted to convert each characters of the string to ascii and pass it to uart. I have used String to byte array function for the same. Was wondering if there is a direct function.

 

Regards

sarkar

0 Kudos
Message 17 of 23
(1,473 Views)
How is the UART connected to your computer? Are you taking about a serial port on your computer?

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 18 of 23
(1,470 Views)

I am using a DB9 connector to pass serial data between two PCs.

0 Kudos
Message 19 of 23
(1,467 Views)

Ah, well you are over-thinking the problem. LV is a much more sophisticate language that incorprates serial drivers that handle all the data serialization and IO for you. Check out the serial IO examples that ship with LV and see if they get you pointed in the right direction.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 20 of 23
(1,459 Views)