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
NewbyNewby 

substring in apex code

 

Hi All,

 

I want to get first two characters from first name and first 2 characters from the last name and then concatenate and save the result of it in the nick name in apex code while creating the user.

 

Can someone please help me with the code.

 

Thanks

 

PrakashbPrakashb

you can use,

 

String concat = FirstName.substring(0,2) + LastName.substring(0,2);

Trailhead PlatformDevTwoTrailhead PlatformDevTwo
public with sharing class StringToDateConversion {

    public static Date ParsedDate (String DateString) {
        String values;
        String month;
        String year;
        String day;
        for(integer i = 0; i < DateString.length(); i++) {
            if(i<4) {
                year = DateString.substring(0,4);
            } 
            if(i>=4 && i<=5) {
                month = DateString.substring(4,6);
            } 
            if(i>=6 && i<=7) {
                day = DateString.substring(6,8);
            }   
        }
        Date mydate = Date.newInstance(integer.valueOf(year),integer.valueOf(month),integer.valueOf(day));
        return mydate;
    }
}
Use this string method to convert yyyymmdd format to date.Use this code it helps.