Home >Web Front-end >JS Tutorial >Detailed explanation of hyphens in JavaScript_javascript tips

Detailed explanation of hyphens in JavaScript_javascript tips

WBOY
WBOYOriginal
2016-05-16 17:12:031425browse

I spent 2 hours at night to use Javascript to process a simple string filtering function. The code is pasted below. It is actually very simple. I just want to remove Filter out.

A very important reason why it takes so much time is that I am not familiar with the character concatenation operation of JavaScript. JS does not support =, so you need to use a=a 'b'. In fact, this problem is very simple when you think about it, but I don't know why it took a lot of time.

Copy code The code is as follows:

function ProcessString(string){
var i= 0;
var leftTagFlag = false
var clearString = new String();//no tag string
alert("string.length = " string.length);
while( i < string.length){
switch(string.charAt(i)){
case '<': leftTagFlag = true;
break;
case '>': leftTagFlag = false;
break;
case '/':
case 'b': if(leftTagFlag)
break;
else clearString.concat( string.charAt(i) );
default: clearString = clearString.concat( string.charAt(i) );
}  
i ;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn