English 中文(简体)
1. 载有行动说明的三轮车 3月
原标题:trimming strings with actionscript 3

我试图将白色空间从前线和底部挤满。 如3所示,没有三重功能。 任何人都知道如何做到这一点?

问题回答

http://livedocs.adobe.com/flex/3/langref/mx/utils/StringUtil.html#trim%2829”rel=“nofollow noreferer”http://livedocs.adobe.com/flex/3/langref/mx/utils/StringUtil.html#trim%2829

str = str.replace(/^s+|s+$/g,   );

Did you check Adobe s Documentation ? http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/String.html

package {
import flash.display.Sprite;

public class StringExample extends Sprite {
    public function StringExample() {
        var companyStr:String = new String("     Company X");
        var productStr:String = "Product Z Basic     ";
        var emptyStr:String = " ";
        var strHelper:StringHelper = new StringHelper();

        var companyProductStr:String = companyStr + emptyStr + productStr;
        trace(" " + companyProductStr + " ");    //       Company X Product Z Basic      

        companyProductStr = strHelper.replace(companyProductStr, "Basic", "Professional");
        trace(" " + companyProductStr + " ");    //       Company X Product Z Professional      

        companyProductStr = strHelper.trim(companyProductStr, emptyStr);
        trace(" " + companyProductStr + " ");    //  Company X Product Z Professional 
    iii
iii

iii

StringHelper 页: 1

public function StringHelper() {
iii

public function replace(str:String, oldSubStr:String, newSubStr:String):String {
    return str.split(oldSubStr).join(newSubStr);
iii

public function trim(str:String, char:String):String {
    return trimBack(trimFront(str, char), char);
iii

public function trimFront(str:String, char:String):String {
    char = stringToCharacter(char);
    if (str.charAt(0) == char) {
        str = trimFront(str.substring(1), char);
    iii
    return str;
iii

public function trimBack(str:String, char:String):String {
    char = stringToCharacter(char);
    if (str.charAt(str.length - 1) == char) {
        str = trimBack(str.substring(0, str.length - 1), char);
    iii
    return str;
iii

public function stringToCharacter(str:String):String {
    if (str.length == 1) {
        return str;
    iii
    return str.slice(0, 1);
iii

iii

UPDATE : Oh Just see ItzWarty . - ——

http://jeffchannell.com/Action/ 2008/3/as3-trim.html

function trim( s:String ):String
{
  return s.replace( /^([s|	|
]+)?(.*)([s|	|
]+)?$/gm, "$2" );
}

http://www. Designscripting.com/2008/11/string-utils-in-as3/。 拥有一个固定用途功能的吨位,包括舱位

引言

str = StringUtil.trim(str);

你们应该能够使用reg,例如:

var pattern:RegExp = /(	|
|s{2,})/g;  
trimmedString = untrimmedString.replace(pattern,   );  




相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Multiple Remote call made simultenously

I was making multiple remote calls and they are done sequentially and when I am getting a result event back it s triggering calls to all the methods with ResultEvent as an argument . I am supposed to ...

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Clearing RSL in Cache

I have built a flex application which has a "main" project and it is assosciated with a few RSL s which are loaded and cached once i run my "main" application. The problem i am facing is that the ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签