Home > Web Front-end > JS Tutorial > body text

Detailed explanation of hyphens in JavaScript_javascript tips

WBOY
Release: 2016-05-16 17:12:03
Original
1359 people have browsed it

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 ;
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!