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
bprakashbprakash 

can any tell me how to find first space in a string(means position of space in string)

MPS 00:E0:81:C2:DA:55 [days] [r]

 

this is the string i want the first space length so that i can use in my apex code.This all iam doing in a class,i had find a function on fromula fields but it has no use in apex.

can any tell me how to find first space in a string(means position of space in string)

Thanks

Bhanu

Best Answer chosen by Admin (Salesforce Developers) 
steve456steve456

Integer sIndexValue = ord.Email_Address_Client__c.indexOf('@');
String sEmail = ord.Email_Address_Client__c.subString(0, sIndexValue);

 

 

In similar way u can use it for space

All Answers

steve456steve456

Integer sIndexValue = ord.Email_Address_Client__c.indexOf('@');
String sEmail = ord.Email_Address_Client__c.subString(0, sIndexValue);

 

 

In similar way u can use it for space

This was selected as the best answer
bprakashbprakash

iam using this in a email services class,but the thing is that i had a space after MPS iwant the position for that,but everytime it is showing as 0,so how exactly i can get this position of space every time.

for example

this is my string 'NEW ADD'

in this i need the position between NEW & ADD.

Can this is possible ?

Please hepl me out of this.

Thanks

Bhanu

 

 

JPClark3JPClark3
string str = 'NEW ADD';
integer location = str.IndexOf(' ');

 

bprakashbprakash

i got it,i had given any space between ' '

that is the problem,

Thanks for the help,Have a great weekend.

Thanks

Bhanu

 

bprakashbprakash

Thanks

steve,JP clark

have a great weekend