TypeScript String Split

[Pages:3]TypeScript String Split

To split a String in TypeScript, you can use String.split() function. The syntax of the split method is provided below: mystring.split([separator][, limit]); where mystring is split into limit number of splits with separator as delimiter.

Basic Example to Split String in TypeScript

In this example, we will split the string with separator passed as argument. example.ts var str = new String("Apple--Basket--Share--Options") var splits = str.split("--") console.log(splits) Convert this to JavaScript tsc example.ts example.js var str = new String("Apple--Basket--Share--Options"); var splits = str.split("--"); console.log(splits); Run it on a browser.

Split String with a limit on the number of splits

In this example, we will split the string with separator and also the number of splits passed as arguments.

example.ts

var str = new String("Apple--Basket--Share--Options") var splits = str.split("--", 3) console.log(splits)

Convert this to JavaScript

tsc example.ts

example.js

var str = new String("Apple--Basket--Share--Options"); var splits = str.split("--", 3); console.log(splits);

Run it on a browser.

TypeScript

TypeScript Tutorial TypeScript Variables TypeScript if TypeScript if-else TypeScript Switch TypeScript For Loop TypeScript While Loop TypeScript Do-While Loop TypeScript Arrays TypeScript Tuples TypeScript Unions TypeScript Functions TypeScript Anonymous Functions

TypeScript Object Oriented Concepts

TypeScript Class TypeScript Inheritance TypeScript Method Overriding TypeScript Interface

TypeScript String Operations

TypeScript String Length TypeScript String Split

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download