string - c# split and reverse sentence with two languages -
i have sentence (in hebrew,rtl):
ואמר here אוראל
now, when insert array got:
- array[0] = אוראל
- array[1] = was
- array[2] = here
- array[3] = :ואמר
now, because hebrew rtl language need reverse english letters , need switch positions. notice need take care of sentence (which means can have more 2 english words).
how result following?
ואמר ereh saw אוראל
i thought maybe build time new string english words,reverse , build original string again, or maybe use in ref strings...
thanks helping still got problem! had splited sentence said,i reversed array , got this:
לארוא ereh saw רמאו
after step 2 postions of hebrew words worng! in step 3 reversed hebrew words again , got:
אוראל ereh saw ואמר
and need switch position(one in one, said can have sentence lot of words..) so, didn't understand how "put array string together"(step 5)
paolo did hard work of figuring out algorithm:
- split sentence array of strings
- reverse array
- if word not in hebrew reverse it
- join strings
here more elegant version using linq:
var result = sentence .split(' ') .reverse() .select(w => ishebrew(w) ? w : new string(w.reverse().toarray()) .join(" ")
Comments
Post a Comment