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
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.