String Array Clear

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
User avatar
Alan_37
Posts: 179
Joined: Sun May 01, 2016 8:36 pm
Has thanked: 51 times
Been thanked: 54 times
Contact:

String Array Clear

Post by Alan_37 »

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

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: String Array Clear

Post by mnf »

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

User avatar
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

Post by Benj »

Hello,
If it's just a single string - setting s[0] = 0 effectively marks it as a null string.
This would also do the same thing, but only works for a single 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.

User avatar
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

Post by Alan_37 »

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

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: String Array Clear

Post by mnf »

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.

Post Reply