- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个字符串,例如 9.555.555,00,我想删除所有符号并只保留数字,这是字符串格式。
我正在使用 indexof 来查找特殊字符,然后使用循环以便在循环到达它时跳过特定字符,这样它就不会将该字符附加到最终字符串。
但是,执行此操作时,代码似乎拾取了第一次出现的句点符号,但随后 indexOf() 第二次返回 -1,即使还有另一个 .在字符串中。
int dotIndex, commaIndex;
dotIndex = tempBalance.indexOf('.');
commaIndex = tempBalance.indexOf(',');
for(int j = 0; j < tempBalance.length(); ++j){
//System.out.println("Iteration: " + j + " ~ i @ : " + i);
if(j == dotIndex){
System.out.println("Current dot Index: " + dotIndex + " J: " + j + " : " + tempBalance);
dotIndex = tempBalance.indexOf(j+1, '.');
System.out.println("New dotIndex: " + dotIndex);
continue;
} else if(j == commaIndex){
break;
} else {
tempString.append(tempBalance.charAt(j));
//System.out.print("Found normal Number: " + tempBalance.substring(j, (j+1)));
}
system.out.println 的输出:
Current dot Index: 1 J: 1 : 9.955.458,23
New dotIndex: -1
最佳答案
dotIndex = tempBalance.indexOf(j+1, '.');
应该是
dotIndex = tempBalance.indexOf('.', j+1);
但这不是唯一的问题。修复了 '.'
之后。您还需要解决所有 ','
的解析问题。简单地修复上面的问题仍然只会返回 9955458
减去 23
关于java - 使用 indexOf() 两次未能检测到第二个字符的出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17784676/
我想检索字符串列表中的行号(从文件加载)。Indexof 似乎完全匹配。有没有办法检索带有通配符版本的 Indexof 的行?类似于 SL.Indexof('?sometext')? 谢谢! 最佳答案
我已经解析了一些 JSON,但我想获取从 JSON 获得的链接,在链接中找到一个使其不同的标识符(例如 www.foo.com/IDENTIFIER/home),并拥有该标识符作为一个字符串插入到另一
我正在浏览 jQuery 的源代码并碰到这个: return indexOf.call( array, elem ); - Line 683 我想知道这背后的逻辑是什么,为什么不这样做: return
我正在从一个带有空格后的非组合变音符号的字符串中创建一个子字符串。这样做时,我使用 .Contains() 检查字符串。然后执行子串。当我使用空格时 char内部 .IndexOf() ,程序按预期执
我正在使用 Jayway JsonPath 库版本 2.4.0。在 jsonPath 中使用 indexOf 函数,例如。 $.values[?(@.num.indexOf('101') != -1)
由于某种原因,GWT 模拟(客户端)jdk 方法 indexOf() 无法按预期工作。 示例:. 我有一个包含 3 个 NaN 对象的列表: List doubleList = new ArrayLi
Resharper 推荐我使用: int notesFirstSpaceIndex = notes.IndexOf(" ", StringComparison.Ordinal); 代替: int no
我想 String.indexOf(char)比String.indexOf(String)使用单个字符和单个字符串时(例如,'x' & "x") 为了确保我的猜测,我编写了如下简单的测试代码。 pu
我在 IE 8 中的数组顶部使用了 indexOf 方法,但它给出了错误(因为不支持它)。我选择使用 underscore.js 库。我用了_.indexOf(array, value, [isSor
这个问题已经有答案了: No overload for method, takes 0 arguments? (1 个回答) 已关闭 7 年前。 我似乎无法弄清楚为什么我总是收到此错误。 No ove
在 Firefox 和 Opera 上使用 Javascript 调用 indexOf 时出错。在 IE 中工作正常。 错误信息如下: 行动 function anonymous(Grid, Row,
在第一次渲染Use Effect时遇到一个特定的错误,我不确定如何解决。我认为这与该功能的异步性有关,但不确定。项目是一个Reactjs,Firebase,FiRestore Todo应用程序,根据用
在第一次渲染Use Effect时遇到一个特定的错误,我不确定如何解决。我认为这与该功能的异步性有关,但不确定。项目是一个Reactjs,Firebase,FiRestore Todo应用程序,根据用
我需要创建一个对字符串进行排序的函数。字符串中的每个单词都将包含一个数字。数字可以是 1 到 9(不能是 0)。 例如输入:“is2 Thi1s T4est 3a”,函数应返回“Thi1s is2 3
有没有一种方法可以在 Java 中使用 indexOf 在单个解析中查找给定文本中多个字符串的位置? 例如,我想在一次文本解析中为“你”和“ session ”做一个 indexOf“你今天能参加 s
我正在使用以下代码来搜索字符串中的值。 if (myValue.indexOf("Call") > -1) { //dosomething } 我该怎么做和或? (myValue.indexOf("
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
This question already has an answer here: Reference - What does this regex mean? (1 个回答) 1年前关闭。 我必须在
我把它写进了一个 REPL: case class Thingy(s: String) val things = List(Thingy("x"), Thingy("y")) things.index
在带有此查询的 JMESPath 中: people[].{"index":@.index,"name":name, "state":state.name} 在此示例数据上: { "people"
我是一名优秀的程序员,十分优秀!