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 ...
 
随机推荐
- ubuntu16.04 安装opencv3.4
			
1.去官网下载opencv,在本教程中选用的时opencv3.4.1,其他版本的配置方法异曲同工. 下载链接http://opencv.org/releases.html,选择sources版本 2. ...
 - 业务逻辑:shiro框架的功能实现
			
思路:分别在web.xml配置过滤器以及在applicationContext.xml去配置 实现步骤:1.在pom.xml里引入shiro的坐标 2.在web.xml里配置shiro过滤器 3.在a ...
 - 在PyCharm 软件中设置你的项目 使用的Python版本
			
在PyCharm 软件中设置你的项目 使用的Python版本 python2 和 python3 有很大的不同,使用python2 编写的程序,如果使用python3 就运行不了:使用python3编 ...
 - c# 新中新二代身份证阅读,包含头像,支持华视
			
需要用到dll和文件: 其中3个dll文件是需要调用的dll,license.dat文件为解压图片的授权文件 以下是需要用到的dll里面的方法: /************************端口 ...
 - php学习笔记-逻辑运算符
			
$a and $b 只有当$a和$b都是true才返回true,否则false. $a or $b 只要$a或者$b至少有一个是true则返回true.意思是或者$a是true,或者是$b是true, ...
 - PDF的一些工具
			
PdfStreamDumper Pdftk 这里有一个链接,列出了很多pdf免费工具 https://en.wikipedia.org/wiki/Category:Free_PDF_software ...
 - R: 绘图 barplot
			
问题:barplot 18.5.16 怎么绘制 barplot,用两种方式:基础绘图 & ggplot2解决方案: 基础绘图 barplot(height, width = 1, space ...
 - 获取iframe自适应后的宽高
			
1.同域 一:引入jquery <script type="text/javascript" src="../jquery.min.js">< ...
 - 转:IDEA 与 eclipse 的部分区别!
			
Idea 与 Eclipse 快捷键的区别,上为Eclipse的快捷键,下为Idea的快捷键查找类名CTRL + SHIFT + RCTRL + N 查找JAR包中的类CTRL + SHIFT + T ...
 - 为所有的Ul下的li标签添加点击事件