gpt4 book ai didi

java - 在 String 类中使用 lastIndexof() 分隔名字和姓氏

转载 作者:行者123 更新时间:2023-11-29 07:37:56 25 4
gpt4 key购买 nike

<分区>

我写了一段代码,在名称字符串中分隔名字和姓氏:

public class NameSeperator {
public static void main(String[] args)
{
String custName="Your Name";
int index;
String firstName;

index=custName.indexOf(" ");


**int last=custName.lastIndexOf("")**;
firstName=custName.substring(0,index);
String lastName=custName.substring(index+1,last);

// get the first name
System.out.println("First Name = "+firstName);
System.out.println("Last Name = "+lastName);
}

}

我用过

int last=custName.lastIndexOf("") 

这里只用了“”,但这里取的是完整的字符串。“”是指调用特定字符串方法的完整字符串吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com