有没有做头像的网站,网站建设和管理自查报告,合肥seo招聘,html5网站建设企业论文字符串转义符号为 \ 常见的转义字符 转移字符对应的英文是 escape character , 转义字符串#xff08; Escape Sequence #xff09; 字母前面加上捺斜线 来表示常见的那些不能显示的 ASCII 字符 . 称为转义字符 . 如 \0,\t,\n 等#xff0c;就称为转 义字… 字符串转义符号为 \ 常见的转义字符 转移字符对应的英文是 escape character , 转义字符串 Escape Sequence 字母前面加上捺斜线 来表示常见的那些不能显示的 ASCII 字符 . 称为转义字符 . 如 \0,\t,\n 等就称为转 义字符因为后面的字符都不是它本来的 ASCII 字符意思了。 常用方法 1. length() 字符个数 2. equals equalsIgnoreCase 方法 3. trim 方法 4. substring 方法 5. concat 方法用于将指定的字符串参数连接到字符串上。 6. contains() 判断是否包括某字符串返回的是 true false 7. indexOf 返回子串的位置索引没有返回 -1 8. lastIndexOf 返回子串的位置索引没有返回 -1 9. replace 替换返回 10. split 拆分为 String[] 11. toLowerCase toUpperCase 转换小写大写 转义字符 所有的转义字符和所对应的意义 文本块 text block 文字块 text blocks 这个特性首先在 JDK 13 中以预览版的形式发布。在 JDK 14 中改进的文 字块再次以预览版的形式发布。最后文字块在 JDK 15 正式发布。 在没有使用文字块之前我们项目中也许有这样的一串代码 String htmlString
!DOCTYPE html\n
html\n body\n h1\Hello World!\/h1\n /body\n
/html\n;
System.out.println(htmlString); 字符串截取案例// linux /usr/local/jdk/
//windows d:\\jdk\\jdk-17
String file c:/user/abc/upload/xxsfasf.afasf-asfas.jpg;
//求出文件目录 c:/user/abc/upload/
//求出文件名称 xxsfasf.afasf-asfas.jpg
//求出文件的扩展名 jpg
//将字符串替换为c:/user/abc/upload/20211202154333.jpgjava11 字符串新特性方法package cn.ex;
import java.io.File;
import java.util.UUID;
/**
* author webrx
* since 17
*/
public class Ex2 {
public static void main(String[] args) {
String p d:/xxx/user/user_abc.jpg;
System.out.println(p);
//File.separator 是根据系统返回相关的符号 linux / windows \ \\
String fc File.separator;
fc p.indexOf(fc) -1 ? / : fc;
System.out.println(fc);
String path p.substring(0, p.lastIndexOf(fc)).concat(fc);
System.out.println(path);
String name p.substring(p.lastIndexOf(fc) 1);
System.out.println(name);
String ext name.lastIndexOf(.) -1 ? :
name.substring(name.lastIndexOf(.) 1);
System.out.println(ext);
UUID uuid UUID.randomUUID();
String newp String.format(%s%s.%s, path, uuid, ext);
System.out.println(newp);
}
} java 11 string api// 判断字符串是否为空白.isBlank(); // true
// 去除首尾空格 .trim()Javastack .strip(); // Javastack
// 去除尾部空格Javastack .stripTrailing(); // Javastack
// 去除首部空格Javastack .stripLeading(); // Javastack
// 复制字符串
Java.repeat(3); // JavaJavaJava
// 行数统计
A\nB\nC.lines().count(); // 3
String str Java;
// 小于0java.lang.IllegalArgumentException
System.out.println(str.repeat(-2));
// 等于0空白串
System.out.println(str.repeat(0));
// JavaJavaJava
System.out.println(str.repeat(3));
// java.lang.OutOfMemoryError
System.out.println(str.repeat(Integer.MAX_VALUE));
// 4
System.out.println(A\nB\nC\rD.lines().count());
String s1 hello java 1.8 ;
System.out.println(s1);
//.concat() 方法相当于 属性字符串连接
System.out.println(hello.concat(\s.repeat(30)).concat(java19));
System.out.println(hello \s.repeat(30) java19);
//清除首尾连续空格
System.out.println(s1.trim());
System.out.println(s1.strip());
System.out.println(s1.stripLeading());
System.out.println(s1.stripTrailing());
//清除所有空格
System.out.println(s1.replace( ,));System.out.println(------------);
System.out.println(.isBlank());
System.out.println(.isEmpty());
System.out.println( .isBlank());//true
System.out.println( .isEmpty());//false
System.out.println( .trim().length() 0 ? 空字符串 : 正确);
System.out.println( .isBlank() ? 空字符串 : 正确);
System.out.println(*.repeat(60));
System.out.println(------------);
//求字符串中行数
System.out.println(hello\njava\nok\n123\nmysql);
System.out.println(hello\njava\nok\n123\nmysql.lines().count()); 判断一个对象是否属于一个类可以用关键字instanceof它是二元操作符格式为
对象 instanceof 类名
式子的值为一个布尔值(boolean)Object sth;
boolean isString sth instanceof String;或者if (sth instanceof String) {
// your code
}字符串添加方法
序
号
方法描述
1 public StringBuffer append(String s) 将指定的字符串追加到此字符序列。
2 public StringBuffer reverse() 将此字符序列用其反转形式取代。
3 public StringBuilder delete(int start, int end) 移除此序列的子字符串中的字符。
4 public insert(int offset, int i) 将 int 参数的字符串表示形式插入此序列中。
5 insert(int offset, String str) 将 str 参数的字符串插入此序列中。
6 replace(int start, int end, String str) 使用给定 String 中的字符替换此序列的子字符串
中的字符。1 int capacity() 返回当前容量。
2 char charAt(int index) 返回此序列中指定索引处的 char 值。
3 void ensureCapacity(int minimumCapacity) 确保容量至少等于指定的最小值。
4
void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) 将字符从此序列复制到目
标字符数组 dst 。
5 int indexOf(String str) 返回第一次出现的指定子字符串在该字符串中的索引。
6
int indexOf(String str, int fromIndex) 从指定的索引处开始返回第一次出现的指定子字符
串在该字符串中的索引。
7 int lastIndexOf(String str) 返回最右边出现的指定子字符串在此字符串中的索引。
8 int lastIndexOf(String str, int fromIndex) 返回 String 对象中子字符串最后出现的位置。
9 int length() 返回长度字符数。
10 void setCharAt(int index, char ch) 将给定索引处的字符设置为 ch 。
11 void setLength(int newLength) 设置字符序列的长度。
12
CharSequence subSequence(int start, int end) 返回一个新的字符序列该字符序列是此
序列的子序列。
13
String substring(int start) 返回一个新的 String 它包含此字符序列当前所包含的字符子
序列。
14
String substring(int start, int end) 返回一个新的 String 它包含此序列当前所包含的字
符子序列。
15 String toString() 返回此序列中数据的字符串表示形式。