You need to sign in to do that
Don't have an account?
sreeja
salesforce development for getting the right allignment
String s1 = 'Hello Max';
String s2 = s1.right(3);
System.assertEquals( 'Max', s2);
for this scenario i have created the apex calss ;
public class testing {
public string result{get;set;}
public void m1(string name){
string trname =name.right(3);
result = trname;
}
}
visualforce page:
<apex:page>
<apex:form>
<apex:commandbutton value="editedname" action="{!m1}" />
<apex:inputtext label="Enter your name" value="{!name}"
{!result}
</apex:form>
</apex:page>
the scenario is , need an inputfield , if you enter in the filed the last value should have to trim and have to display in the visualforce page..
iam in confusion how it can be acheived.
String s2 = s1.right(3);
System.assertEquals( 'Max', s2);
for this scenario i have created the apex calss ;
public class testing {
public string result{get;set;}
public void m1(string name){
string trname =name.right(3);
result = trname;
}
}
visualforce page:
<apex:page>
<apex:form>
<apex:commandbutton value="editedname" action="{!m1}" />
<apex:inputtext label="Enter your name" value="{!name}"
{!result}
</apex:form>
</apex:page>
the scenario is , need an inputfield , if you enter in the filed the last value should have to trim and have to display in the visualforce page..
iam in confusion how it can be acheived.
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Visualforce:
Controller:
You can use substringAfter(separator) which returns the substring that occurs after the first occurrence of the specified separator.
More information: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm#apex_System_String_substringBefore
Or you can use below code also:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Visualforce:
Controller:
You can use substringAfter(separator) which returns the substring that occurs after the first occurrence of the specified separator.
More information: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm#apex_System_String_substringBefore
Or you can use below code also:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
i have to use the leftpad and rightpad methods like this...
public class TrimStringC {
public string result {get;set;}
public string input1 {get;set;}
public string input2 {get;set;}
public void m1 (){
string trname1 = input1.leftPad(18);
string trname2 = input2.leftPad(18);
result = trname +trname2 ;
}
}
visualforcepage;;
<apex:page controller="TrimStringC">
<apex:form >
<apex:commandbutton value="editedname" action="{!m1}" />
<apex:inputtext label="Enter your name" value="{!input1}"/>
<apex:inputtext label="Enter your name" value="{!input2}"/>
<br/>
{!result}
</apex:form>
</apex:page>
-- if i i give the values of Samsung as input1 and iphone as input2, and click on the button , it should display as the
' Samsung iphone' , padding of the two components should be of 18digits ..
You can use input.substring(input.lastIndexOf(' ')+1) to get the last word of a string which is separated by space.
public class TrimStringC {
public string result {get;set;}
public string input {get;set;}
public void m1 (){
String trname = input.substring(input.lastIndexOf(' ')+1);
result = trname;
}
}
hope you understand the scenario.
thanks
String input='hello ';
Integer inputLength = input.length();
Integer ExpectedStringLen = 20;
Integer i;
for(i=0;i<ExpectedStringLen - inputLength;i++)
{
input = ' '+input; //append space before the string. To append space after the string input = input + ' ';
}
I hope this works for the scenario you explained above.
Regards.