9 Strings
1 Strings
1.1 Strings and GStrings
Groovy允许你使用2种不同类型的字符串类型,分别是java.lang.String和groovy.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的更多相关文章
- Hacker Rank: Two Strings - thinking in C# 15+ ways
March 18, 2016 Problem statement: https://www.hackerrank.com/challenges/two-strings/submissions/code ...
- 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 ...
- Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- [LeetCode] Add Strings 字符串相加
Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. ...
- [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 ...
- [LeetCode] Group Shifted Strings 群组偏移字符串
Given a string, we can "shift" each of its letter to its successive letter, for example: & ...
- [LeetCode] Isomorphic Strings 同构字符串
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- [LeetCode] Multiply Strings 字符串相乘
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- 使用strings查看二进制文件中的字符串
使用strings查看二进制文件中的字符串 今天介绍的这个小工具叫做strings,它实现功能很简单,就是找出文件内容中的可打印字符串.所谓可打印字符串的涵义是,它的组成部分都是可打印字符,并且以nu ...
- LeetCode 205 Isomorphic Strings
Problem: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if ...
随机推荐
- POJ 3580 SuperMemo (FHQ_Treap)
题意:让你维护一个序列,支持以下6种操作: ADD x y d: 第x个数到第y个数加d . REVERSE x y : 将区间[x,y]中的数翻转 . REVOLVE x y t :将区间[x,y] ...
- Easyui datebox单击文本框显示日期选择 eayui版本1.5.4.1
Easyui默认是点击文本框后面的图标显示日期,体验很不好,所以我想单击文本框就显示日期选择框,网上很多版本是1.3,1.4的,于是自己就比葫芦画瓢改了一个1.5.4.1的版本. 我参考了网上这个帖子 ...
- 10.model/view实例(4)
任务:给表单的每一列添加列名. 思考: 1.只需要添加一个函数 headerData(). 横向方面添加列名 代码如下: QVariant MyModel::headerData(int sectio ...
- clone方法详解
http://blog.csdn.net/zhangjg_blog/article/details/18369201/
- 安装postman工具模拟请求
扩展工具->: 注意,在创建快捷方式后,第一次打开这个工具,会让你注册信息,忽略它.关闭,重新打开postman工具,然后如下所示:
- virtualbox复制虚拟机网络问题
virtulbox复制虚拟机由于mac地址问题会导致网卡不可以用 1:修改mac地址 需要在virtualbox修改虚拟机网络选项卡下面的mac地址 2:修改ifcfg-eth0 把HWADDR的值设 ...
- Android的性能优化
ArrayList和Vector ArrayList和Vector都是内部以数组实现的List,它们两唯一的区别就是对多线程的支持,ArrayList是线程不安全的,而Vector内部对大多数方法都做 ...
- [译]Javascript数列filter方法
本文翻译youtube上的up主kudvenkat的javascript tutorial播放单 源地址在此: https://www.youtube.com/watch?v=PMsVM7rjupU& ...
- iframe加载的文档高度
var clientHeight = $("#iframe").contents().find("body").height();
- Mac下的UI自动化测试 (三)
使用sikuli进行UI自动化测试固然是方便很多,不用一切都使用AppleScript那烦人的语法,只要界面的UI没有变化,结构的变化不会影响到基于sikuli的自动化,但是基于AppleScript ...