function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
empiimp11empiimp11 

Syntax for "FIND" string function?

The Visualforce Developers Guide has this to say about the FIND String Fuction: 

FIND

Returns the position of a string within a string of text represented as a number. 

But it doesn't give an example or show the specific syntax. How many parameters are accepted? What's the order of the parameters? Can you specify what character position to start searching at?  

 

I tried: Integer position = FIND(solution, ',');

But get: 
Error: Compile Error: Method does not exist or incorrect signature: FIND(String, String) at line 19 column 36 
I tried a number of other combinations with no luck.  Searching for "find string function" didn't help.
RichFaces.tabPanel['ApexClassEditPage:theTemplate:theForm:thePageBlock:theTabPanel']={'ontabchange':'','id':'ApexClassEditPage:theTemplate:theForm:thePageBlock:theTabPanel'} ;
Best Answer chosen by Admin (Salesforce Developers) 
rocwilcoxrocwilcox

Oh.. duh.

 

No, thats at VF Formula funtion you cant use it in a controler.

The "String" object has has the indexOf method

 

String myString;

myString = 'ABCDECFGC';

Integer i = myString.indexOf('C',0);

  returns 2 (I think, 0 indexed)

Integer i = myString.indexOf('C',4);

  returns 5 (start searching at postion 4) 

 

Look for "string methods" in the Apex language reference. 

 

All Answers

rocwilcoxrocwilcox

I was able to use it in a rendered tag:

rendered="{! 3=FIND('this','i') }"

 

Its signature is String, String  and it returns an Integer.

 

What exactly is the code you were using (bigger section of the VF page)?

empiimp11empiimp11

I'm trying to use it in an apex controller extension:

 

    public List<String> solutions {

        get{

         // this function builds the list of SelectOptions for the Solution field   

            List<String> labels = new List<String>();

            String lastLabel = '';

            // do describe here to get the Solution__c field picklist values

            Schema.DescribeFieldResult solutionDFR = Schema.sObjectType.AccountPenetration__c.fields.SolutionArea__c;

            for (Schema.PickListEntry solutionPickVal : solutionDFR.getPicklistValues()){

                String solution=solutionPickVal.getLabel();

                 Integer position = FIND(solution, ',');

// Do a substring here to put the first item (comma separated) into "solution" 

                 if (solution != lastLabel) {

                    labels.add(solution);

                }

                lastLabel = solution;

            }

            return labels;

        }

        set;

    }

 

rocwilcoxrocwilcox

Oh.. duh.

 

No, thats at VF Formula funtion you cant use it in a controler.

The "String" object has has the indexOf method

 

String myString;

myString = 'ABCDECFGC';

Integer i = myString.indexOf('C',0);

  returns 2 (I think, 0 indexed)

Integer i = myString.indexOf('C',4);

  returns 5 (start searching at postion 4) 

 

Look for "string methods" in the Apex language reference. 

 

This was selected as the best answer
empiimp11empiimp11

I just found the "split" function which was what I started looking for at the beginning...

 

Using this now:

                String solution=solutionPickVal.getLabel().split(',')[0];

 

But I'd still like to know if "find" works in a controller extension. 

empiimp11empiimp11
I was looking for string functions, not methods... Thank you for the help!