如何从WebHarvest中提取后替换字符串?

时间:2015-07-05 15:34:33

标签: webharvest

我想将我从网站提取的记录插入到DB中,但提取文本包含符号撇号,并且在sql插入期间导致语法错误。我可以在WebHarvest中知道如何用“'”代替撇号吗?

提前致谢!

1 个答案:

答案 0 :(得分:0)

我通常使用script元素处理字符串,然后输出到新的webharvest变量。例如:

    <var-def name="r_output">
        A long string with lots of funny characters
new lines and & and ' single and " double quotes
    </var-def>

    <var-def name="r_output2">
        <script return="r_output2">
          <![CDATA[
             String r_output2 = "\n" + r_output.toString().replaceAll("&", "&amp;").replaceAll("\\t","").replaceAll("\\n","").replaceAll("\\r","");
           ]]>
        </script>
    </var-def>

    <var name="r_output2"/>

作为附注,不是引用引号中的撇号,而是引用整个数据块,例如:"a string with a ' single quote"而不是a string with a "'" single quote

相关问题