+ Start a Discussion
smith indiasmith india 

how to get string size ? and how to check each character of the string ?

Jia HuJia Hu
String str = 'abcdefg';
System.debug('size: ' + str.length() );
for(integer i = 0; i < str.length(); i++) {
System.debug(' character ' + i + ' = ' + str.substring(i, i + 1) );
}
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.