Searching for a string within a string

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Gypo
Posts: 52
Joined: Thu Apr 29, 2010 11:12 am
Has thanked: 5 times
Been thanked: 3 times

Searching for a string within a string

Post 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
The only real simulation isn't ...
Gypo

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: Searching for a string within a string

Post 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.

Gypo
Posts: 52
Joined: Thu Apr 29, 2010 11:12 am
Has thanked: 5 times
Been thanked: 3 times

Re: Searching for a string within a string

Post 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
The only real simulation isn't ...
Gypo

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: Searching for a string within a string

Post 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 );

Gypo
Posts: 52
Joined: Thu Apr 29, 2010 11:12 am
Has thanked: 5 times
Been thanked: 3 times

Re: Searching for a string within a string

Post 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
The only real simulation isn't ...
Gypo

Gypo
Posts: 52
Joined: Thu Apr 29, 2010 11:12 am
Has thanked: 5 times
Been thanked: 3 times

Re: Searching for a string within a string

Post 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
The only real simulation isn't ...
Gypo

Post Reply