Mateo B.
Mateo B.

Reputation: 21

Replace Character in a String during a While Loop in Java

Why doesn't this work?

while ((line = file.readLine()) != null) {
            String myLine = line;
            input += "[" + myLine.replace(":", "]") + '\n';
            }

The leading "[" is inserted with the line followed by a new line(\n) but it doesn't replace my character even though it occurs on each line.

As you can tell I am opening a file, reading it line by line, and attempting to modify each line in turn. Everything works fine except for the character replace.

This is my sample text.

gen|1|1|בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃ 

This is what I want.

[gen|1|1|]בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽר 

This is what I get.

[gen|1|1|בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃ 

Thanks for your help as I am new here and to programming.

Upvotes: 2

Views: 437

Answers (1)

Klitos Kyriacou
Klitos Kyriacou

Reputation: 11642

That's because the input text doesn't contain a colon. The character that looks like a colon is actually "׃" U+05C3 : HEBREW PUNCTUATION SOF PASUQ.

Trying using "\u05C3" instead of ":".

Upvotes: 3

Related Questions