㈠ java 如何在字符串查找最后字符的位置
import java.util.Scanner;
public class Test60023{
public static void main(String []args){
int index,i,n,j;
char ch;
String str;
Scanner in=new Scanner(System.in);
ch=(in.nextLine()).charAt(0);
n=in.nextInt();
in.nextLine();
for(i=1;i<=n;i++){
str=in.nextLine();
index=str.lastIndexOf((int)ch);
if(index==-1)
System.out.println("Not found");
else
System.out.println(index);
}
}
}
㈡ java 如何判断一个字符在字符串中最后出现的位置
String n="";
n=n.subString(0,n.lastIndexOf("f"));
截取N中,第0个位置到最后一个f之前的内全部字符容
㈢ 正则表达式怎么匹配字符串中最后一串数字
1、创建java类,TestRegexp
㈣ 正则表达式怎么匹配字符串中最后一串数字
1、创建java类,TestRegexp
㈤ java提取最后一个字符,怎么弄啊!急急急
先用lastIndexOf()得到最后字符的位置的‘值’,然后用substring(‘值’)提取
用法:
String s="Create a new class named Sentence.java. In the main method, write a program that reads a sentence using a dialog box. Depending on the last character of the sentence, output another dialog box identifying the sentence as declarative (ends with a period), interrogative (ends with a question mark), exclamatory (ends with an exclamation point), or other. Use a switch structure to accomplish this.“;
不知道你是要得到this还是最后的标点符号
如果是this:
int index=s.lastIndexOf("this");
String ss=s.substring(index,s.length()-1);
如果就是标点符号:
String ss=s.substring(s.length()-1);
ss就是你要的字符,纯手打希望帮助你。
㈥ java中怎么获取指定字符串的最后一个字符
String ss = titleChoose2B;
char[] c = ss.toCharArray();
int length = c.length;
char b = c[length-1];
㈦ java中替换String中的最后一个字符
替换最后一个字符实现方式有两种:
1:使用replace替换方法
String str="hello world";
str=str.replace(str.charAt(str.length-1)+"","新字符");
2:编写代码替换
String str="hello world";
char[] items=str.toCharArray();
itms[items.length-1]='新字符';
㈧ java 中lastIndexOf();是做什么用的
是String类对象常用的方法,
主要用于字符串截取!
int java.lang.String.lastIndexOf(String str)
返回最右边出现的指定子字符串在此字符串中的索引。
参数:要查找的字符
返回:最末尾一个要查找字符的索引
㈨ java中怎样判断字符串最后一个字符
publicclassTest{
publicstaticvoidmain(String[]args){
来//假设要判自断的字符串str="qwer"
Stringstr="qwer";
//使用length()方法判断这个字符串的长度
inti=str.length();
//使用String类的substring方法显示最后一个字符
System.out.println(str.substring(i-1));
}
}
代码实现如上所示(substring用法题主最好自行网络学习)
㈩ java中怎么获取指定字符串的最后一个字符
用String类的substring(int from,int to)方法去截字符串版位置为from到to-1位置的字符
substring(int index)方法去截字符串位置index-1及以后的所有权字符串,注意字符串的字符位置是从0开始的,substring(int from ,int to)方法是前闭后开的,即[from,to),可以理解为[from,to-1]
例:String name="helloworld";
System.out.println(name.substring(name.length()-1,name.length()));//输出d
System.out.println(name.substring(name.length()-1));//输出d