Hi is there a function to flush / Clear a string Array
I know I can do Array[0] = 0 and so on or a loop that goes true all the array and set
all the elements to 0.
I was hoping something more simple like Array = "" which does not work
also tried a c# icon with Array.Clear(FCV_Array, 0, FCV_Array.Length);
also does not work
Any suggestions, Please
String Array Clear
Moderator: Benj
-
- Valued Contributor
- Posts: 1200
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
- Contact:
Re: String Array Clear
Hi Alan,
What do you actually have - do you have an array of strings or just a single string?
If it's just a single string - setting s[0] = 0 effectively marks it as a null string.
You could use a loop - or use memset (in a C block) - though this is effectively a loop.
(for(I = 0; I < sizeof(s); I++) s = 0;) You can get the array size if you use a macro....
(Note that some implementations 'might' optimise this to use word or long writes - but probably not)
If it's an array of strings - you can still clear the whole block in a single loop.
(for(I = 0; I < sizeof(s) * numberOf(s); I++) …. in pseudocode)
Martin
What do you actually have - do you have an array of strings or just a single string?
If it's just a single string - setting s[0] = 0 effectively marks it as a null string.
You could use a loop - or use memset (in a C block) - though this is effectively a loop.
(for(I = 0; I < sizeof(s); I++) s = 0;) You can get the array size if you use a macro....
(Note that some implementations 'might' optimise this to use word or long writes - but probably not)
If it's an array of strings - you can still clear the whole block in a single loop.
(for(I = 0; I < sizeof(s) * numberOf(s); I++) …. in pseudocode)
Martin
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: String Array Clear
Hello,
Array = ""
If you have a 2D array then you would have to cycle through each string value.
Array[idx][0] = 0
or
Array[idx] = ""
Where idx is 0 to array size -1.
This would also do the same thing, but only works for a single string.If it's just a single string - setting s[0] = 0 effectively marks it as a null string.
Array = ""
If you have a 2D array then you would have to cycle through each string value.
Array[idx][0] = 0
or
Array[idx] = ""
Where idx is 0 to array size -1.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Alan_37
- Posts: 179
- Joined: Sun May 01, 2016 8:36 pm
- Has thanked: 51 times
- Been thanked: 54 times
- Contact:
Re: String Array Clear
Hi, it is just a 1d Array that is storing bytes from an sd card file.
Array = "" dose not work .
I just need to clear it as my problem is when for example first I populate the array with "123456789"
then if I use it again to have it populated with "abc" I get a result of "abc456789"
the only way I found that works is getting the Array length to a variable and loop to set elements to 0 ( Array[idx] =0 )
I also tried to use a circular buffer for this but the data get erased after I read from it, for some reason is not permanent
until i flush
Array = "" dose not work .
I just need to clear it as my problem is when for example first I populate the array with "123456789"
then if I use it again to have it populated with "abc" I get a result of "abc456789"
the only way I found that works is getting the Array length to a variable and loop to set elements to 0 ( Array[idx] =0 )
I also tried to use a circular buffer for this but the data get erased after I read from it, for some reason is not permanent
until i flush
-
- Valued Contributor
- Posts: 1200
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
- Contact:
Re: String Array Clear
Looks like the assignment of 'abc' - needs to add a '\0' (end of string or EOS) character s[3]=0 - can you post your code that is doing the assignment?
Martin.
Martin.