[转]字符串比较的问题 急求高手解答

http://bbs.9ria.com/viewthread.php?tid=76299&extra=page%3D1%26amp%3Borderby%3Ddateline%26amp%3Bfilter%3D2592000

是这样的,我想比较两个字符串:
aStr:String = "abcd";
bStr:String = "dcba";
我希望两个字符串只要内容里面的字母都有一样的就判断相等,
即我希望 可以得到 aStr 和 bStr 相等的结果
可是不知道如何做判断,希望有高人指教。


var abc:String = "asd";
                                var bac:String = "dsa";
                                var bSome:Boolean;
                                for (var i:int = 0; i < abc.length; i++){
                                        var str:String = abc.charAt(i);
                                        for (var j:int = 0; j < bac.length; j++){
                                                if (str == bac.charAt(j)){
                                                        bSome = true;
                                                        break;
                                                }
                                                else {
                                                        bSome = false;
                                                }
                                        }
                                }
                                if (abc.length != bac.length){
                                        bSome = false;
                                        trace("循环过后结果是: 长度不一样");
                                }
                                
                                if(bSome){
                                        trace("循环过后结果是: 相同");
                                }
                                else {
                                        trace("循环过后结果是: 不同");
                                }




var aStr:String = "abcd";
                        var bStr:String = "dcba";
                        trace(compareArray(aStr, bStr));
                
                
                private function compareArray(a:String, b:String):Boolean
                {
                        var i:int;
                        var j:int;
                        var c:String = "";
                        var d:String = "";
                        if (a.length >= b.length)
                        {
                                c = a;
                                d = b;
                        }
                        else
                        {
                                c = b;
                                d = a;
                        }
                        for (i = 0; i < c.length; i++)
                        {
                                var n:int = 0;
                                for (j = 0; j < d.length; j++)
                                {        
                                        if(d.charAt(j) != c.charAt(i))
                                                n++;
                                }
                                if (n == d.length)
                                {
                                        return false;                                        
                                }                                
                        }                                
                        return true;
                }

你可能感兴趣的:(C++,c,PHP,C#,J#)