You need to sign in to do that
Don't have an account?
empiimp11
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'} ;
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 |
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
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)?
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;
}
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.
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.