Compare javascript strings with
来源:互联网 发布:中国外债数据 编辑:程序博客网 时间:2024/05/16 10:00
/*By Jiangong SUN*/
Today I wanted to compare two string in javascript, they both have the same values but they are not equal when i compare them.
Here is my html code:
<div class='A'><span>3</span><span>6</span><span>-&-n-b-s-p-;</span><span>7</span><span>5</span><span>9</span><span>,</span><span>0</span><span>0</span><span>€</span></div><div class='B'>36 759,00 €</div>
My js code :
var stringA = '';$.each($('.A'), function(){ stringA += $(this).text();});stringA = $.trim(stringA).replace(" ", "");var stringB = $.trim($('.B').text()).replace(" ", "");//localeCompare is a method for compare string in javascript//0 : It string matches 100%.//-1 : no match, and the parameter value comes before the string object's value in the locale sort order//1 : no match, and the parameter value comes after the string object's value in the locale sort ordervar equals = stringA.localeCompare(stringB);
Finally, my code doesn't work 'cause it always return -1, but not 0.
After struggling during hours, I thought it's the problem of " ";
I use the unicode of " ", and it works!!!! It's strange, but at least it works for me now !!!!
stringA = stringA.replace("/\u00a0/g", "");
Enjoy coding !!!
- Compare javascript strings with
- JavaScript closure: compare with Java
- Compare Strings
- Compare Strings
- How to compare two strings with Linq to Entity
- Compare strings in java
- Case ignore compare strings
- #55 Compare Strings
- [Amazon] Two Strings Are Anagrams (Compare Strings)
- strcmp, stricmp — compare strings.
- 【LintCode】 Compare Strings 比较字符串
- Lintcode55 Compare Strings solution 题解
- [LintCode]Compare Strings(C++|Python)
- compare signed with unsigned
- compare with zero value
- sipXecs compare with Asterisk
- compare with two XML
- debug compare with release
- TESA28 - Datorteknik Y (Datorteknik avdelning)
- c++运算!!
- 你爱曼联的什么
- VC 多线程编写
- NHibernate配置入门
- Compare javascript strings with
- 在线WEB GUI设计工具
- ejb 学习
- Java学习方法的一点个人见解-完整版[转]
- joomla Strict Standards: Accessing static property JCache
- 一定要讨好自己
- 我的超长综合面经
- C++ 编码风格精简
- 大众点评网客户端