2

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.

3
  • 1
    What does the contents of your file look like? Commented Sep 29, 2016 at 23:22
  • 5
    Show us some sample input, expected output, and actual output. Commented Sep 29, 2016 at 23:24
  • 1
    I've added some samples. Commented Sep 29, 2016 at 23:41

1 Answer 1

3

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 ":".

Sign up to request clarification or add additional context in comments.

4 Comments

Actually, this won't work, because that character is actually the last character in the right-to-left Hebrew portion of text.
Great tip! That was definitely the issue, however it inserts my bracket at the end of line instead of at the same location as my replaced symbol. As you just said.
Yes, I realised that after I posted. It's because there's both left-to-right and right-to-left text mixed in each line. The "׃" is actually the last character in the right-to-left text. When you replace it with "]" it goes at the end because "]" is a left-to-right character. I think you may have to do some sophisticated regular expression matching to solve this one.
Thanks so much. I can do that. Any recommendations for docs to read on for conversion between Hebrew and English.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.