Page 1 of 1

Searching for a string within a string

Posted: Wed Sep 15, 2010 9:52 am
by Gypo
Hi

Is there a function in FC 4 (PIC) that would do the same as the visual basic command instr?
Basically instr is used to see if one string exists anywhere within another string. It returns the position where the string is found. If it is not found then it returns 0.

I have attempted in FC to search through a string from the first character in the string and move along each time it fails, I did that by taking a part of the larger string into a temp string and comparing that with the one I was looking for...

I can sort most things out in C but as I am new(ish) to it, it gets time consuming and very frustrating, but will try till I am grey :lol: (Ooopps too late)
My attempt at this with FC just kept locking up the program, got big and messy so stopped and thought of looking for a C solution.

Should I be able to do this with the flowcode components (building blocks) or should I do it in C?

Can we have a FC function to do this in future versions?? :roll:

Regards

Re: Searching for a string within a string

Posted: Wed Sep 15, 2010 10:18 am
by Benj
Hello Gypo,

I've just had a quick look through the BoostC manual and there is a C function that will do the job your looking for.

The manual can be found here:

Program Files\Matrix Multimedia\Flowcode v4\BoostC\boostc.pdf

The function you require looks like this.

char* strstr( const char *ptr1, const char *ptr2 )

I will add your suggestion to the list for future revisions.

Re: Searching for a string within a string

Posted: Wed Sep 15, 2010 10:35 am
by Gypo
Ben

Many thanks 8) , I'll make use of that command.

I take it I can access the variables that I use in FC within the C code as long as I use the full name given to it by FC (not tried that yet!).

Thanks again Ben

Regards

Re: Searching for a string within a string

Posted: Wed Sep 15, 2010 2:16 pm
by Benj
Hi Gypo,

Yes you should be able to reference Flowcode variables in C by capitalising the variable name and adding a prefix FCV_.

eg

"var1" become "FCV_VAR1" in C code.

For the function parameters you will also need to use the * to tell the compiler that you are passing a pointer reference to the variable.

eg

FCV_RESULT = strstr( *FCV_VAR1, *FCV_VAR2 );

Re: Searching for a string within a string

Posted: Wed Sep 15, 2010 3:15 pm
by Gypo
Ben

Thanks, the first part was what I was thinking of, however, I'd forgot about the pointers and so the second bit is a great help as I'd have missed that.

I'm going to try it out on a new FC project just to try and build the function then import it...

Thanks again

Re: Searching for a string within a string

Posted: Wed Sep 15, 2010 7:10 pm
by Gypo
Ben

I took the code and put it into a new project to test the ability to change FC values in C code.

I created 3 variables (result, var1 & var2) assigned "A0123456789A" to var1 and "6" to var2 in FC using a string function.
I addded a C function to the project and put what I thought would be what was needed to change one of the FC variables to "888" but no joy

I looked in the BC manual and it doen't seem to show anymore than what you put, I looked on the web and found some code, tried that and still no joy.

Any pointers / help would be appreciated

The simple project attached

Thanks
Str_IN_Str.fcf
Trying to change FC variable from C code
(4 KiB) Downloaded 273 times