java怎么获取字符串中指定的值?

[复制链接]
查看11 | 回复5 | 2017-9-28 01:20:44 | 显示全部楼层 |阅读模式
用subString.具体用法:字符串截取,substring(int beginIndex) 返回一个新的字符串,它是此字符串的一个子字符串。substring(int beginIndex, int endIndex)返回一个新字符串,它是此字符串的一个子字符串。beginIndex - 起始索引(包括)。从0开始endIndex - 结束索引(不包括)。"12345".substring(3) returns "45""12345".substring(2, 3) returns "23"...
回复

使用道具 举报

千问 | 2017-9-28 01:20:44 | 显示全部楼层
你如果知道其具体位置 可以用substring ()去截取如果有特定的特定的分隔符 如“;” 可以用split(“;”)去直接转数组如果都不知道,悲剧了,循环 一个个去找,一个个判断char c; for(int i=0;i<str.length;i++){c = str.get(i) 。。。 }...
回复

使用道具 举报

千问 | 2017-9-28 01:20:44 | 显示全部楼层
public class Hello{public static void main(String[] args){String str = "12345";String[] arr = new String[str.length() - 2];for(int i = 0,j = 2; i < arr.length; i++){if(i ...
回复

使用道具 举报

千问 | 2017-9-28 01:20:44 | 显示全部楼层
package com.minrisoft;public class fm {public static class StringConcatenation {
public static void main(String[] args) { String message3="So say we all!";
...
回复

使用道具 举报

千问 | 2017-9-28 01:20:44 | 显示全部楼层
用substring吧String str="12345";String s1=str.substring(0,1);//s1为1String s2=str.substring(1,3);//s1为2String s3=str.substring(3,5);//s1为3...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行