如何删除 ActionScript 中以特殊字符(或单词)开头的部分字符串?

发布于 2024-08-26 13:53:18 字数 95 浏览 5 评论 0原文

所以我有一个字符串“bla dla dla vre bla 54312”我想通过说类似的话将其变成“bla dla dla” 函数(字符串,“vre”); 怎么做这样的事情?

so I have a string "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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓦然回首 2024-09-02 13:53:18

我确信您知道如何围绕此编写函数,但这就是您真正需要做的事情。查看 liveDocs 以获取有关 subString 和 indexOf 方法的详细信息。

var newString:String;

newString = "bla dla dla vre bla 54312"

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

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"));
旧时模样 2024-09-02 13:53:18

这可能会帮助您开始:

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]);
}

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]);
}
狼性发作 2024-09-02 13:53:18

我不熟悉动作脚本语法,但这似乎相当简单。你可以尝试:

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

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

我可能有一些语法错误,但基本概念仍然清晰。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文