是否可以从文本区域的html页面粘贴中找到这样的标记,并用javascript代码中提到的另一个标记替换它的标记? HR-CT 我的 我感到满溢 我 我 g UIP集合 M C D

是否可以从文本区域的html页面粘贴中找到这样的标记,并用javascript代码中提到的另一个标记替换它的标记? HR-CT 我的 我感到满溢 我 我 g UIP集合 M C D,javascript,java,jquery,html,Javascript,Java,Jquery,Html,预期产出:- <HTML> <HEAD> </HEAD> <BODY> <TABLE> <TR> <TD ROWSPAN="1" COLSPAN="1"> <P CLASS="text">HR-CT</P> </TD> <TD ROWSPAN

预期产出:-

<HTML>

<HEAD>
</HEAD>

<BODY>
    <TABLE>
        <TR>
            <TD ROWSPAN="1" COLSPAN="1">
                <P CLASS="text">HR-CT</P>
            </TD>
            <TD ROWSPAN="1" COLSPAN="1">
                <P CLASS="Tab-Text-7">my
                    <EM CLASS="Math-B">i</EM> Stackoverflow
                    <EM 
                    CLASS="Math-B">i</EM>
                    <EM CLASS=
                    "Math-B">i</EM>
                    <EM CLASS="Math-B">g</EM> UIP-Muster
                    <EM CLASS="Math-B">m</EM>
                </P>
            </TD>
        </TR>
        <TR>
            <TD>
                <EM CLASS="hoch">C</EM>
                <EM CLASS="Math-C">d</EM>
            </TD>
        </TR>
    </TABLE>
</BODY>

</HTML>
(“g”应替换为“⇔;”)。
(“i”应替换为“~;”)。
使用下面的代码,我可以轻松地替换所有这些标记,但我希望将其转换为javascript代码,这样它就可以从文本区域读取数据,然后用另一个标记替换所有这些标记

Java代码:

("<EM CLASS="Math-C">g</EM>", should be replaced with "&#8660;").
("<EM CLASS="Math-B">i</EM>", should be replaced with "&#126;").
FileInputStream-fstream;
FileOutputStream-fout;
数据输入流in1;
缓冲剂;
BufferedWriter bw=null;
字符串htmlText=null;
弦线;
fstream=新文件输入流(“D:\\Special symbol
文件\\test symbol.htm”);
字符串st=“”;
fout=新文件输出流(“D:\\Special symbol files\\test
符号new.html“,true);
in1=新数据输入流(fstream);
br=新的BufferedReader(新的InputStreamReader(in1,“UTF-8”);
reader=新文件输入流(“D:\\Special symbol files\\test
symbol.htm);;
bw=新的缓冲写入程序(新的输出流写入程序(fout,“UTF-8”));
而((line=br.readLine())!=null)
{
htmlText=htmlText+行;
}
//htmlText=提取文本(读取器);
System.out.println(“html内容:+htmlText”);
System.out.println(“索引:+htmlText.indexOf(“o”);
htmlText=htmlText.replace(“i”,
"~");
htmlText=htmlText.replace(“l”,
“l”);
htmlText=htmlText.replace(“j”,
“j”);
htmlText=htmlText.replace(“g”,
“g”);
/*pattern=pattern.compile(“\\s*m\\s*”);
m=模式匹配器(htmlText);
htmlText=m.replaceAll(“&ge;”)*/
htmlText=regExp(htmlText,“数学B”,“m”,“和ge;”);
htmlText=htmlText.replace(“+”、“÷;”);
htmlText=htmlText.replace(“[”,“&le;”);
htmlText=htmlText.replace(“o”,“和#8595;”);
htmlText=htmlText.replace(“m”、“和”↑;”);
htmlText=htmlText.replace(“u”和“⇒;”);
htmlText=htmlText.replace(“e”)、“⇒;”;
htmlText=htmlText.replace(“t”和“→;”);
htmlText=htmlText.replace(“d”和“→;”);
htmlText=htmlText.replace(“r”和“←;”);
htmlText=htmlText.replace(“b”和“←;”);
htmlText=htmlText.replace(“w”,“和”#8660;”);
htmlText=htmlText.replace(“g”,“和#8660;”);
htmlText=htmlText.replace(“s”、“8656;”);
htmlText=htmlText.replace(“c”和“⇐;”);
htmlText=htmlText.replace(“n”、“8657;”);
htmlText=htmlText.replace(“p”和“⇓;”);
htmlText=htmlText.replace(“v”、“↔;”);
htmlText=htmlText.替换为(“f”、“↔;”;
htmlText=htmlText.replace(“>”,“>\n”);
write(htmlText);
bw.close();
在上面代码的帮助下,我可以替换标记,但我需要将此java代码转换为java脚本,通过该脚本,可以通过单击按钮轻松替换粘贴到文本区域的数据。 (供参考)


任何人都可以帮助我!

你能做的就是创建一个你想这样替换的标签数组

FileInputStream fstream;
    FileOutputStream fout;
    DataInputStream in1;
    BufferedReader br;
    BufferedWriter bw=null;
    String htmlText=null;


    String line;
            fstream = new FileInputStream("D:\\Special symbol 
files\\test symbol.htm");
            String st=" ";
            fout = new FileOutputStream("D:\\Special symbol files\\test 
symbol new.html",true);
            in1 = new DataInputStream(fstream);
            br = new BufferedReader(new InputStreamReader(in1,"UTF-8"));
            reader = new FileInputStream("D:\\Special symbol files\\test 
symbol.htm");           
            bw=new BufferedWriter(new OutputStreamWriter(fout,"UTF-8"));
            while ((line=br.readLine()) != null) 
            {
                htmlText=htmlText+line;
            }
            //htmlText=extractText(reader);
            System.out.println("html content :"+htmlText);
            System.out.println("index:"+htmlText.indexOf("<EM  
CLASS=\"Math-C\">o</EM>"));



            htmlText=htmlText.replace("<EM CLASS=\"Math-B\">i</EM>", 
"&#126;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-B\">l</EM>", 
"<EM CLASS=\"Math-B\">l</EM>");
            htmlText=htmlText.replace("<EM CLASS=\"Math-B\">j</EM>", 
"<EM CLASS=\"Math-B\">j</EM>");
            htmlText=htmlText.replace("<EM CLASS=\"Math-B\">g</EM>", 

"<EM CLASS=\"Math-B\">g</EM>");
             /*pattern = Pattern.compile("<EM CLASS=\"Math-B\">\\s*m\\s*</EM>"); 
             m = pattern.matcher(htmlText);
                htmlText=m.replaceAll("&ge;");*/
            htmlText=regExp(htmlText,"Math-B","m","&ge;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-B\">+</EM>", "&#247;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-B\">[</EM>", "&le;");

            htmlText=htmlText.replace("<EM CLASS=\"Math-C\">o</EM>", "&#8595;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-C\">m</EM>", "&#8593;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-C\">u</EM>", "&#8658;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-C\">e</EM>", "&#8658;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-C\">t</EM>", "&#8594;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-C\">d</EM>", "&#8594;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-C\">r</EM>", "&#8592;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-C\">b</EM>", "&#8592;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-C\">w</EM>", "&#8660;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-C\">g</EM>", "&#8660;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-C\">s</EM>", "&#8656;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-C\">c</EM>", "&#8656;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-C\">n</EM>", "&#8657;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-C\">p</EM>", "&#8659;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-C\">v</EM>", "&#8596;");
            htmlText=htmlText.replace("<EM CLASS=\"Math-C\">f</EM>", "&#8596;");

            htmlText=htmlText.replace(">", ">\n");
            bw.write(htmlText);
            bw.close();

这是一份同样的工作。

这是我问题的解决方案

var originalText = $('#txtArea').val();
var finalText = originalText;

for (var val in array)
   finalText = finalText.replace(new RegExp(val, "g"), array[val]);
$(文档).ready(函数(){
$('#findAndReplace')。在('单击',函数()上){
变量数组={
“(\n |.*)d:”⇔;“,
“(\n |.*)c':“c”,
“(\n |.*)g”:“œ;”,
}
var originalText=$('#txtArea').val();
var finalText=原始文本;
for(数组中的var val)
finalText=finalText.replace(新的RegExp(val,“g”),数组[val]);
$('#txtArea').val(finalText);
});
});
借助于此,我们可以查找和替换多行以及同一行文本。
谢谢@Sushil。

谢谢Sushil我得到了我的解决方案,而且它工作得很好。非常欢迎@poojadeshmukh。很高兴我能帮助你。如果你还需要什么,请告诉我。当然,Sushil。真的很好,从过去4天开始,我无法编写此代码,但你已经完成了,只有通过你的解决方案,我找到了我的答案,并且能够将其编码为pe非常感谢。再次感谢soo Mucht这是我问题的解决方案。借助于此,我们可以找到并替换多行以及同一行文本。tumcha电子邮件id dila nahi tumhiHey@Sushil Hi是否可以在从“上载”按钮上载html文件并应用更改后运行此代码,就像现在输入数据后应用的一样在文本区域。上传后,它将在服务器端的java代码中可用,因此您可以自己应用您对java代码的更改。您可以用演示进行解释吗?我不懂java,因此我无法为此创建演示。不过,我可以帮您处理逻辑。您如何以java获取上传的文件?是流式文件还是获取文本一根绳子?
var originalText = $('#txtArea').val();
var finalText = originalText;

for (var val in array)
   finalText = finalText.replace(new RegExp(val, "g"), array[val]);
$(document).ready(function(){

   $('#findAndReplace').on('click', function(){

     var array = {
        '<EM CLASS="text">((\n|.*?))d</EM>':'&#8660;', 
        '<EM CLASS="data">((\n|.*?))c</EM>':'<sup>C</sup>',
        '<EM CLASS="data1">((\n|.*?))g</EM>':'&#156;',

    }

    var originalText = $('#txtArea').val();
    var finalText = originalText;

    for (var val in array)
        finalText = finalText.replace(new RegExp(val, "g"), array[val]);

    $('#txtArea').val(finalText);


  });

});