html string in c#.net?

Posted by Divs99 under C# on 8/3/2012 | Points: 10 | Views : 4946 | Status : [Member] | Replies : 23
my input html string looks like below

<p>XYZ<br /><br /><br />~~&nbsp;<br />NC ROAD&nbsp;<br />~~<br />LOS ANGELES,&nbsp;TX</p>

i want my output looks like this below

<p>XYZ<br /><br /><br />NC ROAD&nbsp;<br />LOS ANGELES,&nbsp;TX</p>

i tried given below REGULAR EXPRESSION code it DOESNT WORK FOR ME ..PLS HELP ME OUT..

input = System.Text.RegularExpressions.Regex.Replace(input, @"<br[ ]*/>(~~+&nbsp;)*</br[ ]*>", "<br />");




Responses

Posted by: Naraayanan on: 8/3/2012 [Member] Starter | Points: 25

Up
0
Down
Hi ,
try this Code
   string str = "<p>XYZ<br /><br /><br />~~&nbsp;<br />25 IDIOTIC UNDER A ROCK&nbsp;<br />~~<br />LOS ANGELES,&nbsp;TX</p>  ";

string result = str.Replace('~',' ');
string result1 = result.Remove(75, 6);
MessageBox.Show(result1);


Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Divs99 on: 8/3/2012 [Member] Starter | Points: 25

Up
0
Down
my input string will change dynamically based on user input given in html editor....

dont be constant to one input.....

i have to write regular expression on the given input string to get output like

input = System.Text.RegularExpressions.Regex.Replace(input, @"<br[ ]*/>(~~+&nbsp;)*</br[ ]*>", "<br />");


to get result change in above regular expression itself...

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 8/5/2012 [Member] Silver | Points: 25

Up
0
Down

VB .Net:
input = System.Text.RegularExpressions.Regex.Replace(input, "<br\s?\/>[~]+(&nbsp;)?<br\s?\/>","<br/>", RegexOptions.IgnoreCase)

The above regex can replaces as your requirement.

Regards,
Singaravel M

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Divs99 on: 8/5/2012 [Member] Starter | Points: 25

Up
0
Down
if my input string looks like below
string intput= "<p>XYZ<br /><br /><br />~~&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />25 IDIOTIC UNDER A ROCK&nbsp;<br />~~<br />LOS ANGELES,&nbsp;TX</p> ";

your regular expression fails if i gave mroe than one &nbsp;...pls change accrodingly in tht case

input = System.Text.RegularExpressions.Regex.Replace(input, "<br\s?\/>[~]+(&nbsp;)?<br\s?\/>","<br/>", RegexOptions.IgnoreCase)


Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 8/6/2012 [Member] Silver | Points: 25

Up
0
Down

input = System.Text.RegularExpressions.Regex.Replace(input, "(<br\s?\/>)+[~]+(&nbsp;)*(<br\s?\/>)+","<br/>", RegexOptions.IgnoreCase)


Regards,
Singaravel M

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Divs99 on: 8/6/2012 [Member] Starter | Points: 25

Up
0
Down
see my input string

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Divs99 on: 8/6/2012 [Member] Starter | Points: 25

Up
0
Down
if my input string looks liek below format

<p>XYZ<br /><br /><br />~!~&nbsp;&nbsp; <br />NC ROAD&nbsp;<br />~!~<br />LOS ANGELES,&nbsp;TX</p>

my output looks like below

<p>XYZ<br /><br /><br />NC ROAD&nbsp;<br /LOS ANGELES,&nbsp;TX</p>

then it fails ......pls change accrodingly in the below regex code
input = System.Text.RegularExpressions.Regex.Replace(input, "(<br\s?\/>)+[~]+(&nbsp;)*(<br\s?\/>)+","<br/>", RegexOptions.IgnoreCase)




Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 8/6/2012 [Member] Silver | Points: 25

Up
0
Down
input = System.Text.RegularExpressions.Regex.Replace(input, "<br\s*\/>[~\!]+(&nbsp;)*<br\s*\/>","<br/>", RegexOptions.IgnoreCase)




Regards,
Singaravel M

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Divs99 on: 8/6/2012 [Member] Starter | Points: 25

Up
0
Down
iam not abel to replace this one

<br />~!~&nbsp;&nbsp;<br />

by using ur regex code

input = System.Text.RegularExpressions.Regex.Replace(input, "<br\s*\/>[~\!]+(&nbsp;)*<br\s*\/>","<br/>", RegexOptions.IgnoreCase)

pls helpme out..

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 8/6/2012 [Member] Silver | Points: 25

Up
0
Down
attach ur input file

Regards,
Singaravel M

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Divs99 on: 8/6/2012 [Member] Starter | Points: 25

Up
0
Down
iam not using any input file...iam getting input html string when user enters any input in html editor in c#.net..

my input string in below way

<p>XYZ<br /><br /><br />~!~&nbsp;&nbsp; <br />NC ROAD&nbsp;<br />~!~<br />LOS ANGELES,&nbsp;TX</p>

i want output in below way

<p>XYZ<br /><br /><br />NC ROAD&nbsp;<br />LOS ANGELES,&nbsp;TX</p>

just i have to replace

<br />~!~&nbsp;&nbsp; <br /> replace to <br />
<br />~!~<br /> replace to <br />

hwo to replace this combination if my value is blank iam getting this combination in string ~!~...we kept one condition in c#.net

if (sVal == "")
{
sVal = "~!~";
}

the combination ~!~ i have to replace in regex code?






Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Divs99 on: 8/6/2012 [Member] Starter | Points: 25

Up
0
Down
i think space is creating problem here to replace

<br />~!~&nbsp;&nbsp; <br />

here after &nbsp iam getting space thts y it is not replacing to <br/>......how to handle tht one?


Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 8/6/2012 [Member] Silver | Points: 25

Up
0
Down
input = System.Text.RegularExpressions.Regex.Replace(input, "<br\\s*\\/>(~\\!~)+(&nbsp;)*\\s*<br\\s*\\/>", "<br/>", RegexOptions.IgnoreCase)

where u expect space u can use above bolded text...

Regards,
Singaravel M

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Divs99 on: 8/6/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks a lot....it is working fine.....:). I really appreciate for ur help and time too

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Divs99 on: 8/6/2012 [Member] Starter | Points: 25

Up
0
Down
if my input string looks like below

<p>XYZ<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />~!~&nbsp;&nbsp;~!~&nbsp;<br />NC ROAD<br />LOS ANGELES,&nbsp;TX</p>

i have to get output string in below way

<p>XYZ<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />NC ROAD<br />LOS ANGELES,&nbsp;TX</p>

then it fails ..pls modify accordingly the given below regex code


input = System.Text.RegularExpressions.Regex.Replace(input, "<br\\s*\\/>(~\\!~)+(&nbsp;)*\\s*<br\\s*\\/>", "<br/>", RegexOptions.IgnoreCase)







Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 8/6/2012 [Member] Silver | Points: 25

Up
0
Down
input = System.Text.RegularExpressions.Regex.Replace(input, "<br\\s*\\/>((~\\!~)+(&nbsp;)*\\s*)+<br\\s*\\/>", "<br/>", RegexOptions.IgnoreCase)




Regards,
Singaravel M

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Divs99 on: 8/6/2012 [Member] Starter | Points: 25

Up
0
Down
can u pls let me know wht is the differnece between + and * in regex?

* means repeatedly combination come is there any limit for repeatation?

? means wht it will do and is there any limit for repeatation?



Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 8/6/2012 [Member] Silver | Points: 25

Up
0
Down
? means zero or one
* means zero or more
+ means more than zero(i.e. zero not allowed)

Regards,
Singaravel M

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Divs99 on: 8/6/2012 [Member] Starter | Points: 25

Up
0
Down
Thank you very much for ur explanation.........it is working fine

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 8/6/2012 [Member] Silver | Points: 25

Up
0
Down
its okay...

i think below link used for u...

http://msdn.microsoft.com/en-us/library/2k3te2cs(v=vs.80).aspx


Regards,
Singaravel M

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Divs99 on: 8/6/2012 [Member] Starter | Points: 25

Up
0
Down
ok i will refer and let u know if i have any queries...once again Thank you very much .....

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Divs99 on: 8/12/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Sakthi,

pls help me out with this isue if u have any idea?pls go through below link

http://www.dotnetfunda.com/forums/thread10953-getting-blank-page-issue-in-pdf-using-ap-webgrabber.aspx

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Divs99 on: 8/28/2012 [Member] Starter | Points: 25

Up
0
Down

Hi Sakthi,


if my input string looks like below

<p>XYZ<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;~!~&nbsp;&nbsp; ~!~&nbsp; <br />NC ROAD<br />LOS ANGELES,&nbsp;TX</p>

i have to get output string in below way

<p>XYZ<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />NC ROAD<br />LOS ANGELES,&nbsp;TX</p>

then it fails ..pls modify accordingly the given below regex code

input = System.Text.RegularExpressions.Regex.Replace(input, "<br\\s*\\/>((~\\!~)+(&nbsp;)*\\s*)+<br\\s*\\/>", "<br/>",

RegexOptions.IgnoreCase);

here i have to replace <br />&nbsp;~!~&nbsp;&nbsp; ~!~&nbsp; <br /> replace to <br/>

it fails using above regex code becoz here iam getting &nbsp; before this combination ~!~&nbsp;&nbsp; ~!~&nbsp; thts y it is not replacing to single <br/>

Based on user input &nbsp; will come in one case ..in another case it wont come before this combination ~!~&nbsp;&nbsp; ~!~&nbsp;

Divs99, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response