Sweet.apex

  • Docs
  • Tutorials
Docs Menu
  • Sweet.apex Core
    • Transpilation
    • Grammar
    • Command
    • Config
  • Features
    • Action
    • Apex Doc
    • Array Creation
    • Aspect
    • Cast
    • Default Value
    • Enum
    • File
    • Function
    • Identity
    • Injection
    • Lambda
    • Log
    • Mod
    • Not Null
    • Operator
    • Optional
    • Reflection
    • Rethrow
    • Switch
    • Template String
    • Template
    • Script
    • Tagged String
    • Annotation
    • Nullable
    • Var
    • Val
    • Map Access
    • Constructor
    • Transaction
    • Destructure
    • Import Static
    • Pipeline
    • Varargs
    • Patch
    • Import As
  • Plugin Development
    • Feature
    • Test Case

Template String Guide

Template String

Feature Overview

This feature converts a template string into concatenated strings.

Prerequisite

None

Sweet Apex Example

public class TemplateStringDemo {
    public static String a = 'a';
    public static String b = 'b';
    public static String c = `${a}-${b}`;
    public static String text = `
        This is a free style text.
        You can add ${c} here.
        Try it.
        `;
}
 
1
public class TemplateStringDemo {
2
    public static String a = 'a';
3
    public static String b = 'b';
4
    public static String c = `${a}-${b}`;
5
    public static String text = `
6
        This is a free style text.
7
        You can add ${c} here.
8
        Try it.
9
        `;
10
}

Transpiled Apex

public class TemplateStringDemo {
    public static String a = 'a';
    public static String b = 'b';
    public static String c = '' + a + '-' + b + '';
    public static String text = '\n        This is a free style text.\n        You can add ' + c + ' here.\n        Try it.\n        ';
}
6
 
1
public class TemplateStringDemo {
2
    public static String a = 'a';
3
    public static String b = 'b';
4
    public static String c = '' + a + '-' + b + '';
5
    public static String text = '\n        This is a free style text.\n        You can add ' + c + ' here.\n        Try it.\n        ';
6
}

Usage

Contribute on Github! Edit this section.

  • Feature Overview3 sec read
  • Prerequisite1 sec read
  • Sweet Apex Example12 sec read
  • Transpiled Apex12 sec read
  • Usage
    Copy