You need to sign in to do that
Don't have an account?
SFDC New learner
How to transform a given string pattern?
Hi All,
I am trying to transform a string pattern lets say 'aaabbbcccbbsc' to a3b3c3b2s1c1.
Below is the code.
public class StringPracticeduplicatecount {
public void stringpatterns(String s)
{
string newstr;
list<String> liststr=s.split('');
system.debug('::'+liststr);
integer count = 1,i=1;
for (integer j = 0; j < s.length(); j++)
{
if (i<s.length() && liststr[i] == liststr[i - 1])
{
count++;
}
else
{
newstr = newstr + liststr[i - 1] + count;
count = 1;
}
i++;
}
system.debug( 'output: ' + newstr);
}
}
The code is working fine but when i open the debug log it is showing 'List Size is too large to display'.How to avoid this error?
And also I want to know if there is any other approach to get the solution.
Any help is greatly appreciated.
Thanks,
Sirisha
I am trying to transform a string pattern lets say 'aaabbbcccbbsc' to a3b3c3b2s1c1.
Below is the code.
public class StringPracticeduplicatecount {
public void stringpatterns(String s)
{
string newstr;
list<String> liststr=s.split('');
system.debug('::'+liststr);
integer count = 1,i=1;
for (integer j = 0; j < s.length(); j++)
{
if (i<s.length() && liststr[i] == liststr[i - 1])
{
count++;
}
else
{
newstr = newstr + liststr[i - 1] + count;
count = 1;
}
i++;
}
system.debug( 'output: ' + newstr);
}
}
The code is working fine but when i open the debug log it is showing 'List Size is too large to display'.How to avoid this error?
And also I want to know if there is any other approach to get the solution.
Any help is greatly appreciated.
Thanks,
Sirisha
Looks like it giving the correct response. see image.
The error you are getting is obvious. The string that is being passed is too big for System.Debug for printing. Honestly printing that list will not make any sense because you are printing every character in the string as a list. Instead print the string the incoming string and make sense out it.