none
Replace Chinese Kanji character with Japanese Kanji and vice versa. RRS feed

  • Question

  • Hi Everyone,

    Maybe this thread is for someone who knows the difference between Chinese Kanji and Japanese Kanji.

    So, let me ask you a question.

    There are more than two characters in Kanji. Several ones for Chinese and one for Japanese Kanji.

    For example, the word body can be written in Kanji as 體 in Chinese way and 体 in Japanese way.

    But the meanings are same for these characters. And of course, unicodes for these two ones are different.

    So about code, I'm developing a simple software for replacing a certain set of Chinese Kanji characters with Japanese Kanji characters.

    Let's say there is a certain string.

    string str_sentence=僕のは大きいです。(Let's just ignore the meaning).

    So I want to replace  with 体.

    I used below code.

    str_sentence.Replace(體, 体)

    But it didn't work!

    MessageBox.Show(str_sentence) showed original sentence without replacing the character!

    So I assume that actually, .NET regards these two characters as same ones.

    I tested below code.

    if(!= 体)

    {

    MessageBox.Show("Different!")

    }

    And it showed the message.

    What do you think about this?


    Let me sing you forever

    Tuesday, January 20, 2015 4:52 PM

Answers

  • Replace doesn't replace characters 'in-situ'. It returns a new string with the replacement.

    Try str_sentence = str_sentence.Replace(...)

    or var new_sentence = str_sentence.Replace(...)

    Strings in C# are immutable and can't be changed.


    Tuesday, January 20, 2015 10:01 PM

All replies

  • Replace doesn't replace characters 'in-situ'. It returns a new string with the replacement.

    Try str_sentence = str_sentence.Replace(...)

    or var new_sentence = str_sentence.Replace(...)

    Strings in C# are immutable and can't be changed.


    Tuesday, January 20, 2015 10:01 PM
  • Hi Steve,

    Thanks for your answer. Maybe something's wrong with my brain, not with the code.

    Have a nice day! :)


    Let me sing you forever


    • Edited by boladore Tuesday, January 20, 2015 10:39 PM
    Tuesday, January 20, 2015 10:39 PM