1       Strings

1.1  Strings and GStrings

Groovy允许你使用2种不同类型的字符串类型,分别是java.lang.Stringgroovy.lang.GString类。在Groovy中,你也可以定义单行或多行的字符串。

字符串使用””,括起来。ofGString 会自动转换为java.lang.String

package first

class StringTest {

static main(args) {

def name="John"

def s1="Hello $name" //$name将会被替换

def s2="Hello $name"

println s1

println s2

println s1.class

println s2.class

//举例对象引用并方法调用

def date = new Date()

println "We met at $date"

println "We met at ${date.format('yyyy-MM-dd')}"

}

}

 

输出

下边表格中,定义了不同类型的Strings。

Table 2. Define Strings in Groovy

String example

Description

'This is a String'

标准的java String

"This is a GString"

Groovy GString,允许变量替换和方法调用

''' Multiline string (with line breaks)'''

多行string

""" Multiline string (with line breaks)"""

多行GString

/regularexpression/

前后都加/,使得正则表达式更加可读。

tokenize()方法,切割String进入到一个String list,使用空白符作为分隔符。

Groovy JDK增加toURL()到String,意思是允许一个String转为URL。

trim 方法,删除字符串收尾的空白字符(空格)。

1.2  Operator overloading in Strings

String支持操作重载。使用+连接字符串,使用-截取字符串,使用 left-shift追加到字符串。

9 Strings的更多相关文章

  1. Hacker Rank: Two Strings - thinking in C# 15+ ways

    March 18, 2016 Problem statement: https://www.hackerrank.com/challenges/two-strings/submissions/code ...

  2. StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing the strings?

    StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing t ...

  3. Multiply Strings

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  4. [LeetCode] Add Strings 字符串相加

    Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. ...

  5. [LeetCode] Encode and Decode Strings 加码解码字符串

    Design an algorithm to encode a list of strings to a string. The encoded string is then sent over th ...

  6. [LeetCode] Group Shifted Strings 群组偏移字符串

    Given a string, we can "shift" each of its letter to its successive letter, for example: & ...

  7. [LeetCode] Isomorphic Strings 同构字符串

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  8. [LeetCode] Multiply Strings 字符串相乘

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  9. 使用strings查看二进制文件中的字符串

    使用strings查看二进制文件中的字符串 今天介绍的这个小工具叫做strings,它实现功能很简单,就是找出文件内容中的可打印字符串.所谓可打印字符串的涵义是,它的组成部分都是可打印字符,并且以nu ...

  10. LeetCode 205 Isomorphic Strings

    Problem: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if ...

随机推荐

  1. Swing绘图API

    ----------------siwuxie095                             工程名:TestSwingPaintAPI 包名:com.siwuxie095.swing ...

  2. 解析IFC数据并存储到关系型数据库

    即系IFC数据并存储到关系型数据库中,目前解析的IFC文件是两亿多行,构件数量120万

  3. 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-006归并排序(Mergesort)

    一. 1.特点 (1)merge-sort : to sort an array, divide it into two halves, sort the two halves (recursivel ...

  4. 算法Sedgewick第四版-第1章基础-1.4 Analysis of Algorithms-004计算内存

    1. 2. 3.字符串

  5. 1用java实现冒泡排序算法以及解决的几个小问题。

    package huawei.exam; public class BubbleSort { /** * @param args */ public static void main(String[] ...

  6. Entity Framework Tutorial Basics(36):Eager Loading

    Eager Loading: Eager loading is the process whereby a query for one type of entity also loads relate ...

  7. 同一个id出现多条数据的问题

    这是disial出现的一个bug,花了近两天时间才解决,原因,要在dto的类前加上注解,让它延迟加载. -----后期补充.结合代码.

  8. 打印sql语句

    root->trace hibernate->trace ,然后,改配置 全文搜索:show_sql,将所有的show_sql改为true. 这样,就会显示sql语句了.

  9. jQuery 插件开发——countdown(倒计时)

    故事背景:按照惯例,先写下故事背景,其实也是再次汇报下最近开发情况的.做电商的都知道,这是个活动季啊,双十一.双十二.元旦....各种啊..其实说这么多就是想表达最近比较忙.呵呵^_^,正好今天抽点空 ...

  10. EIP权限工作流升级说明-2019/3/5

    首页增加待办事项直接处理按钮 2,新增处理历史记录