Skip to content

Commit

Permalink
Bug Fix: Trim function
Browse files Browse the repository at this point in the history
  • Loading branch information
iewnfod committed Sep 27, 2023
1 parent ed258f8 commit ab4eec1
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion scripts/string.cpc
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,32 @@ FUNCTION Trim(s : STRING) RETURNS STRING
len <- LENGTH(s)
DECLARE result : STRING
DECLARE c : STRING
DECLARE flag : BOOLEAN

// 从前往后查看
flag <- TRUE
FOR i <- 1 TO len
c <- MID(s, i, 1)
IF c <> ' ' THEN
IF c = ' ' AND flag THEN
PASS
ELSE
result <- result & c
flag <- FALSE
ENDIF
NEXT i

// 从后往前查看
s <- result
result <- ""
len <- LENGTH(s)
flag <- TRUE
FOR i <- len TO 1 STEP -1
c <- MID(s, i, 1)
IF c = ' ' AND flag THEN
PASS
ELSE
result <- c & result
flag <- FALSE
ENDIF
NEXT i

Expand Down

0 comments on commit ab4eec1

Please sign in to comment.