Implementation of TRIM () in JavaScript

zhaozj2021-02-16  56

// Turn out before and after the string

Function Jhshtrim (SSTRING)

{

Var stratmp;

StrtMP = JHSHRTRIM (Jhshltrim (SString));

Return strtmp;

}

/ / This function is used to take the SSTRING string before cutting

/ / -------------------------------------------------------------------------------------------- -----------------------------------

Function Jhshltrim (SSTRING)

{

VAR SSTR, I, ISTART, SRESULT = ""

SSTR = SSTRING.SPLIT ("");

iStart = -1;

For (i = 0; i

{

IF (SSTR [I]! = "")

{

iStart = i;

Break;

}

}

IF (iStart == -1) {return "";} // indicates that all characters in SSTRING are spaced, then return to the air string

Else {Return SString.Substring (iStart);

}

//4.2 This function is used to remove the SSTRING string

/ / -------------------------------------------------------------------------------------------- -----------------------------------

Function Jhshrtrim (SSTRING)

{

VAR SSTR, I, SRESULT = "", STEMP = "";

// if (SSTRING.LENGTH == 0) {return "";} // parameter sstring is an empty string

SSTR = SSTRING.SPLIT ("");

For (i = sstr.length - 1; I> = 0; i -) // Remind the string

{

SResult = SRESULT SSTR [I];

}

STEMP = JHSHLTRIM (SRESULT); / / Space Space Turn

IF (STEMP == "") {RETURN "";

SSTR = STEMP.SPLIT ("");

SRESULT = ""

For (i = sstr.length - 1; I> = 0; I -) // Remove the processed string

{

SResult = SRESULT SSTR [I];

}

Return SRESULT;

}

转载请注明原文地址:https://www.9cbs.com/read-16040.html

New Post(0)