当前位置:网站首页>[groovy] string (string splicing | multi line string)
[groovy] string (string splicing | multi line string)
2022-07-05 03:12:00 【Programmer community】
List of articles
- One 、 String type variables
- Two 、 Multiline string
- 3、 ... and 、 Complete code example
One 、 String type variables
In a double quoted string , Use ${ Variable name } String splicing ,
- ${ Variable name } The value of the symbol , Is in Value when defining ;
def s1 = "Hello" def s3 = "${s1} World!!!" s1 = "Hello Groovy" // Modify the spliced function value // The value printed is "Hello World!!!" println s3- ${ -> Variable name } The value of the symbol , Is in Access value , Not when defined , If before the visit , Revised Variable name The corresponding variable value , Then the last value is the modified value ; This is the rule of closure ;
def s1 = "Hello" def s4 = "${->s1} World!!!" s1 = "Hello Groovy" // Modify the spliced function value // The value printed is "Hello Groovy World!!!" println s4stay Single quotation marks in , Cannot perform string connection operation ;
// String splicing is not allowed in single quotation marks def s5 = '${s1} World!!!' // The value printed is "${s1} World!!!" println s5String splicing code example :
// character string def s1 = "Hello" // String splicing // Be careful , String splicing can only be carried out in double quotation marks , Not in single quotes // ${ Variable name } The value of the symbol , Is in Value when defining ; def s3 = "${s1} World!!!" // ${-> Variable name } The value of the symbol , Is in Access value , Not when defined , // If before the visit , Revised Variable name The corresponding variable value , Then the last value is the modified value ; // This is the rule of closure ; def s4 = "${->s1} World!!!" // Modify the spliced function value s1 = "Hello Groovy" // Print respectively s3 String content and type , Modifying the spliced function value does not affect the final string value println s3 println s3.class // Print respectively s4 String content and type // Modify the spliced function value It's affecting Final string value println s4 println s4.class // String splicing is not allowed in single quotation marks def s5 = '${s1} World!!!' // Print respectively s4 String content and type println s5 println s5.classExecution results :
Hello World!!!class org.codehaus.groovy.runtime.GStringImplHello Groovy World!!!class org.codehaus.groovy.runtime.GStringImpl${
s1} World!!!class java.lang.StringTwo 、 Multiline string
stay In a normal string , Use \n Symbol , Represents line feed operation ,
def m1 = "Hello\nWorld"representative
HelloWorldcharacter string ;
stay
6
6
6 Between two double quotes , You can write multiple lines of text directly , Multiline text There are... On the left and right
3
3
3 Double quotes ;
def m2 = """HelloWorld"""representative
HelloWorldcharacter string ;
Code example :
// Multiline string output def m1 = "Hello\nWorld" def m2 = """HelloWorld""" // Print multiline strings println m1 println m2Execution results :
HelloWorldHelloWorld3、 ... and 、 Complete code example
Complete code example :
class Test {
static void main(args) {
// character string def s1 = "Hello" // String splicing // Be careful , String splicing can only be carried out in double quotation marks , Not in single quotes // ${ Variable name } The value of the symbol , Is in Value when defining ; def s3 = "${s1} World!!!" // ${-> Variable name } The value of the symbol , Is in Access value , Not when defined , // If before the visit , Revised Variable name The corresponding variable value , Then the last value is the modified value ; // This is the rule of closure ; def s4 = "${->s1} World!!!" // Modify the spliced function value s1 = "Hello Groovy" // Print respectively s3 String content and type , Modifying the spliced function value does not affect the final string value println s3 println s3.class // Print respectively s4 String content and type // Modify the spliced function value It's affecting Final string value println s4 println s4.class // String splicing is not allowed in single quotation marks def s5 = '${s1} World!!!' // Print respectively s4 String content and type println s5 println s5.class // Multiline string output def m1 = "Hello\nWorld" def m2 = """HelloWorld""" // Print multiline strings println m1 println m2 }}Execution results :
Hello World!!!class org.codehaus.groovy.runtime.GStringImplHello Groovy World!!!class org.codehaus.groovy.runtime.GStringImpl${
s1} World!!!class java.lang.StringHelloWorldHelloWorld
边栏推荐
- 有個疑問 flink sql cdc 的話可以設置並行度麼, 並行度大於1會有順序問題吧?
- Voice chip wt2003h4 B008 single chip to realize the quick design of intelligent doorbell scheme
- C file in keil cannot be compiled
- Apache Web page security optimization
- d3js小记
- LeetCode146. LRU cache
- Apache build web host
- Pdf things
- [micro service SCG] 33 usages of filters
- El select, El option drop-down selection box
猜你喜欢

Tiny series rendering tutorial

Sqoop installation

Anchor free series network yolox source code line by line explanation Part 2 (a total of 10, ensure to explain line by line, after reading, you can change the network at will, not just as a participan

Utilisation simple de devtools

The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety

Design of kindergarten real-time monitoring and control system

this+闭包+作用域 面试题

2.常见的请求方法

Qrcode: generate QR code from text

IPv6 experiment
随机推荐
Is there any way to change the height of the uinavigationbar in the storyboard without using the UINavigationController?
[daily problem insight] Li Kou - the 280th weekly match (I really didn't know it could be so simple to solve other people's problems)
001 chip test
ICSI213/IECE213 Data Structures
What is the most effective way to convert int to string- What is the most efficient way to convert an int to a String?
d3js小记
GFS分布式文件系统
Mongodb common commands
返回二叉树中两个节点的最低公共祖先
College Students' innovation project management system
Returns the lowest common ancestor of two nodes in a binary tree
Linux Installation redis
2021 Li Hongyi machine learning (2): pytorch
TCP security of network security foundation
Performance of calling delegates vs methods
Use UDP to send a JPEG image, and UPD will convert it into the mat format of OpenCV after receiving it
单项框 复选框
VM in-depth learning (XXV) -class file overview
Share the newly released web application development framework based on blazor Technology
問下,這個ADB mysql支持sqlserver嗎?