Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

How to convert HTML using replace or remove commoand in C# or Java

    HTML 1  I m getting this in string ->

    S=        
           "<html>  <head> <link rel='stylesheet' type='text/css'
             href='http://www.taxmann.com/css/taxmannstyle.css' /> 
                 </head>  <body ><html>
                <body style='background-color:Black;font-size:30px;color:#fff;'>
        <div id="digest">
   
                   <p class="threedigest">ST : Extended period of limitation 
                cannot be invoked for not paying tax if there was divergence 
        of opinion during relevant 
                period and 
                some judgments were in favour of assessee, 
                as there could be no suppression/wilful mis-statement
         by assessee</p>
   
                 </div></body></html></body></html>"

Note : I am getting this HTML which is Correct

BUT    String HTML 2 ->

            "<html> 
                     <head> <link rel='stylesheet
                    ' type='text/css' href='http://www.taxmann.com/css/taxmannstyle.css' /> 
                     </head>  <body ><html><body style='background-color:Black;font-size:30px;color:#fff;'>
                    <html>
<head>
                    <link href='http://www.taxmann.com/TaxmannWhatsnewService/Styles/style.css' rel='stylesheet' type='text/css' />
                    
<title>Rs.560-crore tax evasion detected</title>
<style type="text/css">
            
body
                    {font-family:Arial, Helvetica, sans-serif; font-size:12px; 
                line-height:18px;text-align:justify;}
                    
.w100{width:100%;}
.fl-l{float:left;}
.ffla{font-family:Arial, 
                Helvetica, sans-serif;}
                    
.fs18{font-size:18px;}
.mart10{margin-top:10px;}
.fcred{color:#c81616;}
                
.tc{text-align:center;}
.tu{text-transform:uppercase;}
.lh18{line-height:18px;}
</style>
</head>
<body>

                <div class="w100 fl-l">
<div class="w100 fl-l ffla fs18 mart10 fcred ttunderline tc tu">
                    Rs.560-crore tax 
vasion detected</div>

<div class="w100 fl-l lh18 mart10">
                The Central Excise Intelligence, 
Chennai Zone, has detected 164 cases involving excise
                 and service tax evasion of Rs.560 crore in 2012- 13.
     A total of 166 show cause notices
                 have been issued involving Rs.500 crore for 
    various central excise and service 
                tax cases during the year.
 – www.business-standard.com</div>


            </div>
</body>

                    </html>
</body>
    </html></body>
    </html>"

I want to Convert HTML 2 format same as Html1 format I tried Much but unable to do . I have tried to remove Some HTML Content as well but its not worked, I don't know how to convert Html2 same as it Html1 even I have also tried to Remove this using Java But not able to do Please help me ! Using replace or remove command in any programming language.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this its working with removing two unwanted html tags in line one in your code i.e response from server have two html tags because of that your are not getting proper response. Try to remove all unwanted tags and align the html code

public class TestScriptClass {
public static void main(String[] args) {

    String inputValue=" ";
      inputValue =inputValue+"<html><head> <link rel='stylesheet' type='text/css' href='http://www.taxmann.com/css/taxmannstyle.css' />"+ 
                    "</head>  <body ><html><body style='background-color:Black;font-size:30px;color:#fff;'>"+ 
                    "<html>
<head> <link href='http://www.taxmann.com/TaxmannWhatsnewService/Styles/style.css' rel='stylesheet' type='text/css' />"+ 
                    "
<title>Rs.560-crore tax evasion detected</title>
<style type="text/css">"+ 
                    "  
body{font-family:Arial, Helvetica, sans-serif; font-size:12px; "+ 
                    " line-height:18px;text-align:justify;} 
.w100{width:100%;}
.fl-l{float:left;}
.ffla{font-family:Arial, "+ 
                    "Helvetica, sans-serif;} 
.fs18{font-size:18px;}
.mart10{margin-top:10px;}
.fcred{color:#c81616;}"+ 
                    " 
.tc{text-align:center;}
.tu{text-transform:uppercase;}
.lh18{line-height:18px;}
</style>
</head>
<body>
"+ 
                    "  <div class="w100 fl-l">
<div class="w100 fl-l ffla fs18 mart10 fcred ttunderline tc tu">"+ 
                    "   Rs.560-crore tax "+ 
                    "vasion detected</div>

<div class="w100 fl-l lh18 mart10">"+ 
                    " The Central Excise Intelligence, "+ 
                    "Chennai Zone, has detected 164 cases involving excise"+ 
                    "  and service tax evasion of Rs.560 crore in 2012- 13."+ 
                    "  A total of 166 show cause notices"+ 
                    "   have been issued involving Rs.500 crore for "+ 
                    "  various central excise and service "+ 
                    "  tax cases during the year."+ 
                    "– www.business-standard.com</div>

"+ 
                    " </div>
</body>
"+ 
                    "   </html>
</body>"+ 
                    "  </html></body>"+ 
                    "   </html>";

      String resultValue= inputValue.replace("<html><head> <link rel='stylesheet' type='text/css' href='http://www.taxmann.com/css/taxmannstyle.css' /></head>  <body ><html>", " <html><head> <link rel='stylesheet' type='text/css' href='http://www.taxmann.com/css/taxmannstyle.css' />");

      System.out.println(resultValue);       
}
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...