我的备忘录


ActionScript 的字符替换

Posted in Uncategorized by Kafeifei on the 12月 8th, 2006

总之我是没有在帮助里找到,但感觉应该有才对
去google了一下:http://www.jurjans.lv/flash/RegExp.html 这个貌似很变态,但现在我要的只是一个简单的str_replace函数,想了一下,用了个比较变态的方法:

function str_replace(search, replace, subject) {
    var slen = search.length;
    var rstr = '';
    while (true) {
        var find_idx = subject.indexOf(search);
        if (-1 != find_idx) {
            rstr += subject.substr(0, find_idx) + replace ;
            subject = subject.substr(find_idx + slen);
        } else {
            return rstr + subject;
        }
    }
}

4 Responses to 'ActionScript 的字符替换'

Subscribe to comments with RSS or TrackBack to 'ActionScript 的字符替换'.

  1. fmfsaisai said,

    on 12月 25th, 2006 at 11:07 am

    我们公司有人在做新闻模板的替换系统时,就用类似的方法做过。
    大段大段的测量,截取...........(用PHP)
    在我费了九牛二虎之力看明白以后,心里想TMD一个str_replace不就解决了么?
    P.S.他上辈子是C程序员。

  2. Kafeifei said,

    on 12月 25th, 2006 at 11:12 am

    tttt

  3. fmfsaisai said,

    on 12月 25th, 2006 at 11:13 am

    just for test

  4. 小徐 said,

    on 08月 31st, 2008 at 9:16 pm

    呵呵,看看我的实现,转了你的文章,最底有个我自己的实现
    http://hi.baidu.com/phps/blog/item/3f6ed13fecbd25c47c1e7172.html

Leave a Reply


16 项查询 - 2.215 秒