开发者

How to remove part of the string starting from special char (or word) in ActionScript?

开发者 https://www.devze.com 2022-12-23 18:41 出处:网络
so I have a str开发者_StackOverflow中文版ing \"bla dla dla vre bla 54312\" I want to turn it into \"bla dla dla \" by saying something like

so I have a str开发者_StackOverflow中文版ing "bla dla dla vre bla 54312" I want to turn it into "bla dla dla " by saying something like function(string, "vre"); how to do such thing?


I'm sure you know how to write the function around this, but this is all you really need to do what you're asking. Check out the liveDocs for details about the subString and indexOf methods.

var newString:String;

newString = "bla dla dla vre bla 54312"

newString = newString.subString(0,newString.indexOf("vre"));


This might get you started:

var s:String = "bla dla dla vre bla 54312";
var a:Array  = s.split("vre");

if(a) {
    // a[0] should be 'bla dla dla'
    trace(a[0]);
}


I'm not familiar with actionscript syntax, but this seems like it'd be fairly easy. You could try:

function trimStr(myStr, searchStr)
{    
    var index:Int = myStr.search(searchStr);

    if (index > -1)
    {
        return myStr.substring(0, index);
    }
    else
    {
        return myStr;
    }
}

I may've gotten some syntax wrong, but the basic concept still comes through.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号