TypeScript 文字列の前後の空白を削除するサンプル

環境
Windows 11 Pro 64bit
TypeScript 4.4.4

構文
const result: string = 文字列.trim()
trim()は、呼び出した文字列(string)の前後の空白を削除した文字列を返します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const text: string = " s t u d y F "
const result: string = text.trim()
console.log(result)
const text: string = " s t u d y F " const result: string = text.trim() console.log(result)
const text: string = "   s t u d y F "

const result: string = text.trim()

console.log(result)

実行結果
[LOG]: “s t u d y F"

TypeScript

Posted by arkgame