Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current Restore this Version View Version History

Version 1 Next »

今天學到一個可能有用的東西,可以把字串前後不小心多打進去的空白刪除


Check for redundant spaces
var string1 = '    you are a salesman.'
console.log(string1.trim());

var string2 = '       But      you are a salesman.'
console.log(string2.trim());


輸出的結果會是

"you are a salesman."
"But      you are a salesman."


這是js內建的功能,但移除的其實有點陽春,前後或中間刻意多加入一些space的話,結果可能會不一樣。


雖然SyntaxEd App在輸入時應該是不會出現句子首尾有多餘(連續)空白的情況,但未來架構擴充以後很難說。

畢竟現在已經開始考量整合Unity或Unreal的方案了


雖然看到了有用的code片段,卻忘記怎麼用git推上去github,所以只好先來這邊做紀錄


0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.