|
Dear All,
I am doing a XML using C#. I wrote a loop to run foreign and then ordinance tag. While foreign tag running, it performs correctly. Afterwards it run ordinance tag, it gives wrong answer.
The sentence is
<num>7</num><p><text>Indian Penal Code (UK), applicable in Malaysia Indian Penal Code by virtue of the Courts of Judicature Act 1964 s 24(b).</text></p>
It should be replaced properly as
<num>7</num><p><text><strf tblxtract="foreign"><strfact>Indian Penal Code (UK)</strfact></strf>, applicable in Malaysia <strf tblxtract="ordinance"><strfact>Indian Penal Code</strfact></strf> by virtue of the Courts of Judicature Act 1964 s 24(b).</text></p>
Foreign Loop coding lines:
string strContent = "<num>7</num><p><text>Indian Penal Code (UK), applicable in Malaysia Indian Penal Code by virtue of the Courts of Judicature Act 1964 s 24(b).</text></p>";
string strSearch = "Indian Penal Code (UK)"
string strPattern = "([^<strfact])" + strSearch.Replace("(", "\\(").Replace(")", "\\)").Substring(0);
strContent = Regex.Replace(strContent, strPattern , "$1" + "<strf txlxtract="foreign"><strfact>" + strSearch + "</strfact></strf>");
MessageBox.Show(strContent);
Ordinance Loop coding lines:
string strContent = "<num>7</num><p><text>Indian Penal Code (UK), applicable in Malaysia Indian Penal Code by virtue of the Courts of Judicature Act 1964 s 24(b).</text></p>";
string strSearch = "Indian Penal Code"
string strPattern = "([^<strfact])" + strSearch.Replace("(", "\\(").Replace(")", "\\)").Substring(0);
strContent = Regex.Replace(strContent, strPattern , "$1" + "<strf txlxtract="ordinance"><strfact>" + strSearch + "</strfact></strf>");
MessageBox.Show(strContent);
It gives Final Result wrongly:
<num>7</num><p><text><strf tblxtract="foreign"><strfact><strf tblxtract="ordinance" id="TBC"><strfact>Indian Penal Code</strfact></strf> (UK)</strfact></strf> s 20(4), applicable in Malaysia <strf tblxtract="ordinance" id="TBC"><strfact>Indian Penal Code</strfact></strf> by virtue of the Courts of Judicature Act 1964.</text></p>
I dont know where i made a mistake "Indian Penal Code" has replaced twice. Pls help me
|
|
|
|
|
|
|
// |