开发者

Some replace methods are ignored [closed]

开发者 https://www.devze.com 2023-03-09 20:49 出处:网络
It's difficult to tell what is being asked here. This question is 开发者_StackOverflowambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current
It's difficult to tell what is being asked here. This question is 开发者_StackOverflowambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I have multiple replace methods (I mean around 200 replace commands all nested in for loops). But some replace methods don't work at all. I am looping through the file using a For loop:

for(i=0; i<file.length; i++) {

but some replace methods are being ignored. Is there a reason why some methods are being ignored and some aren't?

EDIT1: I'm trying to replace multiple strings in a file.

file[i].replace(str1, str2)
file[i].replace(str3, str4)
file[i].replace(str5, str6)
file[i].replace(str7, str8)
file[i].replace(str9, str10)
...
and so on...

Here's the code:

Click here!


As written, none of the replace statements are doing anything (assuming file is a String[]) because Strings are immutable and replace returns a new String without modifying the original. You'd need to write:

file[i] = file[i].replace(str1, str2);
0

精彩评论

暂无评论...
验证码 换一张
取 消