There is a Pattern that needs to follow:
X? | X, once or not at all |
X* | X, zero or more times |
X+ | X, one or more times |
X{n} | X, exactly n times |
X{n,} | X, at least n times |
X{n,m} | X, at least n but not more than m times |
Code:
string s ='0004400';
string s1= s.replaceFirst('^0{2}','');
system.debug('string is '+s1);
Example
s.replaceFirst('^0{2}',''); output: 0400
s.replaceFirst('^0+',''); output: 400
s.replaceFirst('^0?',''); output: 00400
No comments:
Post a Comment