Hi,
is there a way to make the right header in the RadPrintDocument right aligned so if i have mixed language text (hebrew and english in my case) It will show it right...
currently i use this function (partly taken from this site - c-sharp-split-and-revers-sentence-with-two-languages):
I would like to know if there is a more elegant sollution
is there a way to make the right header in the RadPrintDocument right aligned so if i have mixed language text (hebrew and english in my case) It will show it right...
currently i use this function (partly taken from this site - c-sharp-split-and-revers-sentence-with-two-languages):
public
static
string
ProcessEnglishHebrewSentence(
string
sentence)
{
var ret =
new
List<
string
>();
string
[] words = sentence.Split(
' '
);
var curHebrewList =
new
List<
string
>();
var curEnglishList =
new
List<
string
>();
bool
curLangIsHebrew =
false
;
string
w;
string
reversed;
for
(
int
i = words.Length; i > 0; i--)
{
w = words[i - 1];
if
(System.Text.RegularExpressions.Regex.IsMatch(w, @
"\p{IsHebrew}"
) && curLangIsHebrew)
// we have a word in Hebrew and the last word was in Hebrew too
{
curHebrewList.Add(w);
}
else
if
(System.Text.RegularExpressions.Regex.IsMatch(w, @
"\p{IsHebrew}"
) && !curLangIsHebrew)
// we have a word in Hebrew and the last word was in English
{
if
(curEnglishList.Any())
{
curEnglishList.Reverse();
ret.AddRange(curEnglishList);
}
// reverse current list of English words and add to List
curEnglishList =
new
List<
string
>();
// create a new empty list for the next series of English words
curHebrewList.Add(w);
curLangIsHebrew =
true
;
// set current language to Hebrew
}
else
if
(!System.Text.RegularExpressions.Regex.IsMatch(w, @
"\p{IsHebrew}"
) && !curLangIsHebrew)
// we have a word in English and the last word was in English
{
if
(System.Text.RegularExpressions.Regex.IsMatch(w, @
"[a-zA-Z]"
))
{
reversed =
new
string
(w.Reverse().ToArray());
reversed = reversed.Replace(
"("
,
"^"
);
reversed = reversed.Replace(
")"
,
"("
);
reversed = reversed.Replace(
"^"
,
")"
);
}
else
reversed = w;
curEnglishList.Add(reversed);
// reverse and add it to the current series of English words
}
else
if
(!System.Text.RegularExpressions.Regex.IsMatch(w, @
"\p{IsHebrew}"
) && curLangIsHebrew)
// we have a word in English and the last word was in Hebrew
{
if
(curHebrewList.Any())
{
curHebrewList.Reverse();
ret.AddRange(curHebrewList);
// add current list of Hebrew words to List of Lists
}
curHebrewList =
new
List<
string
>();
// create a new empty list for the next series of Hebrew words
if
(System.Text.RegularExpressions.Regex.IsMatch(w, @
"[a-zA-Z]"
))
{
reversed =
new
string
(w.Reverse().ToArray());
reversed = reversed.Replace(
"("
,
"^"
);
reversed = reversed.Replace(
")"
,
"("
);
reversed = reversed.Replace(
"^"
,
")"
);
}
else
reversed = w;
curEnglishList.Add(reversed);
curLangIsHebrew =
false
;
// set current language to English
}
else
{
throw
new
Exception(
"there should be no other case..."
);
}
}
if
(curHebrewList.Any())
{
curHebrewList.Reverse();
ret.AddRange(curHebrewList);
}
if
(curEnglishList.Any())
{
curEnglishList.Reverse();
ret.AddRange(curEnglishList);
}
return
ret.Aggregate((a, b) => a +
" "
+ b);
}
I would like to know if there is a more elegant sollution