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
streetstreet 

Reading a value after Hiphen from a string

I want to read the value from a string after a Hiphen..

 

Eg:  String s=Red-dy hello;

 

Output should:-   dy hello

RollynRollyn

String methods are available in

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_string.htm

 

String s='Red-dy hello';

 

String stringAfterHyphen = s.split('-')[1];

streetstreet

I need the requirement to implement in VIsualForce page.

 

{!(myStringVariable.split('-')[1])}

 

I have tried this...But throwing an error syntax error 

 

eg: Syntax error. Missing '}'

abivenkatabivenkat

 

hi street,

 

I afraid that how can u use string function in the visual force page??? split is a string function in which u have used it in the visual page. Instead u can use the split function in the controller page. please check it out whether we can use the split function in VF Page or not.

AmitSahuAmitSahu

Street,

 

You cannot use this function in the VF page.

 

Use this in Apex Class (Controller) :

 

String s=Red-dy hello;

 

Public string[] NewS{get;set;}

 

 NewS = s.Split('-')[1];

 

 

Where ever required on VF you can use {!NewS}