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 ...
随机推荐
- cocos2dx中坐标系
CCNode类的setPosition,getPosition函数如果是一个Node的Child则获取的坐标就是该Node的本地坐标 另一个关键问题就是在cocos2d-x里就是各种对象的大小问题.因 ...
- Vue02 样式的动态绑定
daigengxin......2018-3-8 21:09:18 跟angular2类似,分为CSS类绑定和Style样式绑定两种方式,详情参见
- Struts2框架04 struts和spring整合
目录 1 servlet 和 filter 的异同 2 内存中的字符编码 3 gbk和utf-8的特点 4 struts和spring的整合 5 struts和spring的整合步骤 6 spring ...
- redis 有用
浅谈redis (1)什么是redis? Redis 是一个基于内存的高性能key-value数据库. (有空再补充,有理解错误或不足欢迎指正) (2)Reids的特点 redis本质上是一 ...
- php学习笔记-POST和GET的区别
POST和GET都可以用来提交数据. POST方法提交的数据在浏览器的地址栏是不可见的,当然利用一些工具是可以看到的,而GET方法提交的数据在地址栏是可见的.两者比较,POST更安全一点. POST方 ...
- vray学习笔记(5)-学习资料
首先肯定是vray的官方的资料了: 一个是教程 https://docs.chaosgroup.com/display/VRAY3MAX/Tutorials 一个是帮助文件 https://docs. ...
- 李兴华Java培训系列课程
理解程序设计分层的思想: Dao设计模式的组成以及各部分的开发: 3.具体内容 在本次讲解之中,处理IO的部分暂时不会使用到之外,所有Java的重点的核心部分都会涉及到. 实际上在任何的环境下分层的概 ...
- [学习笔记]fork写实复制
#include<stdio.h> #include<stdlib.h> #include<string.h> #include <unistd.h> ...
- Unity串口通信
一.串口简介 串行接口(串口)通常指COM接口,是采用串行通信方式的扩展接口.串口按位(bit)发送和接收字节.尽管比按字节(byte)的并行通信慢,但是串口可以在使用一根线发送数据的同时用另一根线接 ...
- Gazebo学习随记2 SDF和XML
Model 模型 一个模型数据库会拥有的文件 database.config:有关数据库的元数据,从CMakeList自动填充『本地不需要』 model文件夹 一个模型[奏是辣个文件夹]会有的文件 m ...