我正在尝试解析一个字符串,我需要使用子字符串来完成它。该字符串包含撇号字符。我的问题是,如何使用 temp 获取 String.indexOf 来获取撇号字符的索引?
//temp variable currently contains the string 'hello' including the apostrophe character
String finalWord = temp.substring(temp.indexOf('''), temp.indexOf('.'));
最佳答案
你的变量名是错误的(final
是一个保留字),你应该使用转义符:
String finalword = temp.substring(temp.indexOf('\''), temp.indexOf('.'));
关于Java:使用 String.indexOf() 检查撇号字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13384736/