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
Rohit TripathiRohit Tripathi 

Inserting ' before and after value in a list

Hi, as a part of Trailhead challenge, I want to insert a ' before and after value in list. My line of code is :

List1.add(''' +'Test'+ i +''' );

This is throwing error message that : expecting a right parentheses, found ' +'. Could you please suggest what could be done.
Line of code : List1.add( 'Test'+ i ); is working fine. 
Patcs_1Patcs_1
Hi Rohit

it should be like this,

list1.add('\' Test' +i + '\'');// \' (use escape sequence) to print the '.

Thanks

P.S : If this solves your problem, Please mark this as solution by selecting it as best answer.

 
Rohit TripathiRohit Tripathi
Hi,

It worked but Trailhead still shows that challenge is not completed.

Here is my full code :

public class StringArrayTest {
    public static List <String> generateStringArray (Integer n) {
       List<String> List1 = new List<String> ();
        for(Integer i=0;i<n;i++) {
            List1.add('\'Test'+ i+'\'' );
      }
        System.debug(List1);
        return List1;
    } 

}

I am getting following error :

" Challenge not yet complete... here's what's wrong: 
Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings."