我正在使用#include <stdio.h>
int main(void)
{
int a = 0;
int b = 0;
int correctInput=0;
int total_sum = 0;
do
{
printf("Type the first number : \n");
scanf("%d", &a);
printf("Type the second number : \n");
scanf("%d", &b);
if(a<b)
correctInput=1;
else
printf("The second number should be bigger than the first one.\n");
}
while (correctInput ==0) ;
while (a <= b) {
total_sum += a;
a++;
}
printf("Result : %d \n" , total_sum);
return 0;
}
来清除sanitize-html
编辑器的粘贴文本。
让我们说结果可能是像这样的文本字符串
draftJS
现在我需要将<h1 class="title">
President said "<b>Give this man a money</b>" and i agree
</h1
替换为"
或«
取决于条件。
我该怎么做我试图弄清楚我是否可以使用»
draftJS
方法来完成它,但它似乎太复杂了。所以我认为修改html字符串更容易。
答案 0 :(得分:2)
我猜你可以用两个正则表达式来做到这一点:
var inputString = `<h1 class="title">
President said "<b>Give this man a money</b>" and i agree
</h1>`
, startingQuoteRE = / "/g
, endingQuoteRE = /" /g
, outputString = ''
;
outputString = inputString.replace(startingQuoteRE, " «");
outputString = outputString.replace(endingQuoteRE, "» ");
// Or by chaining .replace
// outputString = inputString.replace(startingQuoteRE, " «").replace(endingQuoteRE, "» ");
console.log(outputString);
&#13;
答案 1 :(得分:0)
创建replaceAll
功能。因为replace
函数将替换唯一的第一次出现。
String.prototype.replaceAll = function(string, replace) {
return this.split(string).join(replace);
};
像这样调用函数。
var str = '<h1 class="title">\
President said "<b>Give this man a money</b>" and i agree\
</h1>';
var result = str.replaceAll('"','\'');
console.log(result);