# StringUtil Class

Defined in: `js/util/StringUtil.js:9`
Module: util
Parent Module: StructureJS

The StringUtil...

## Index

Show: Inherited Protected Private Deprecated

### Methods

- createUUID static
- format static
- getExtension static
- paramReplace
- queryStringToObject static
- removeAllWhitespace static
- removeLeadingTrailingWhitespace static
- toCamelCase static
- toConstantCase static
- toPascalCase static
- toSentence static
- truncate static

## Methods

### `createUUID` () String public static

Defined in `js/util/StringUtil.js:128`

Creates a universally unique identifier.

#### Returns:

String:

#### Example:

     StringUtil.createUUID();
     // 'a95d7134-3342-4001-bcea-cc0371b70dec'

### `format`
(

- `str`
- `...rest`

)
String public static

Defined in `js/util/StringUtil.js:238`

Replaces each format item in a specified string with the text equivalent of a corresponding object's value.

#### Parameters:

- `str` String
- `...rest` Array.

#### Returns:

String:

#### Example:

     StringUtil.format('Robert is {0}. Very {0} and {1}!', 'cool', 'smart');
     // 'Robert is cool. Very cool and smart!'

### `getExtension`
(

- `filename`
- `withDot`

)
String public static

Defined in `js/util/StringUtil.js:22`

Gets the extension name off the string being passed in.

#### Parameters:

- `filename` String
- `withDot` Boolean

  If you want the period to be included in the extension name.

#### Returns:

String:

#### Example:

     StringUtil.getExtension('file.exe');
     // 'exe'

     StringUtil.getExtension('file.exe', true);
     // '.exe'

### `paramReplace`
(

- `queryString`
- `name`
- `value`

)
String | Void

Defined in `js/util/StringUtil.js:264`

Updates a value in the query string by its key name.

#### Parameters:

- `queryString` Object
- `name` Object
- `value` Object

#### Returns:

String | Void:

#### Example:

     StringUtil.paramReplace('?name=Robert&age=23&gender=male', 'gender', 'female');
     // '?name=Robert&age=23&gender=female'

### `queryStringToObject`
(

- `queryString`
- `[useParseFloat=false]`

)
Object | Null public static

Defined in `js/util/StringUtil.js:147`

Converts a query string to an object.

#### Parameters:

- `queryString` String
- `[useParseFloat=false]` Boolean optional

  If true converts strings to numbers.

#### Returns:

Object | Null:

#### Example:

     StringUtil.queryStringToObject('?name=Robert&age=23&gender=male');
     // {name: 'Robert', age: '23', gender: 'male'}

     StringUtil.queryStringToObject('?name=Robert&age=23&gender=male', true);
     // {name: 'Robert', age: 23, gender: 'male'}

### `removeAllWhitespace`
(

- `str`

)
String public static

Defined in `js/util/StringUtil.js:181`

Remove all whitespace from the string passed in.

#### Parameters:

- `str` String

#### Returns:

String:

#### Example:

     let str = '   a b    c d e f g ';
     StringUtil.removeAllWhitespace(str);
     // 'abcdefg'

### `removeLeadingTrailingWhitespace`
(

- `str`

)
String public static

Defined in `js/util/StringUtil.js:197`

Remove leading and trailing whitespace.

#### Parameters:

- `str` String

#### Returns:

String:

#### Example:

     let str = '   a b    c d e f g ';
     StringUtil.removeLeadingTrailingWhitespace(str);
     // 'a b    c d e f g'

### `toCamelCase`
(

- `str`

)
String public static

Defined in `js/util/StringUtil.js:76`

Converts a string to a camel case string.

#### Parameters:

- `str` String

#### Returns:

String:

#### Example:

     StringUtil.toCamelCase("liveDown_by-the.River");
     // 'liveDownByTheRiver'

### `toConstantCase`
(

- `str`

)
String public static

Defined in `js/util/StringUtil.js:112`

Converts a string to a constant case string.

#### Parameters:

- `str` String

#### Returns:

String:

#### Example:

     StringUtil.toConstantCase("liveDown_by-the.River");
     // 'LIVE_DOWN_BY_THE_RIVER'

### `toPascalCase`
(

- `str`

)
String public static

Defined in `js/util/StringUtil.js:94`

Converts a hyphen string to a pascal case string.

#### Parameters:

- `str` String

#### Returns:

String:

#### Example:

     StringUtil.toPascalCase("liveDown_by-the.River");
     // 'LiveDownByTheRiver'

### `toSentence`
(

- `str`
- `[separator]`

)
String public static

Defined in `js/util/StringUtil.js:43`

Converts a string to a sentence case string.

#### Parameters:

- `str` String
- `[separator]` String optional

  Can be any string you want to use as a separator.

#### Returns:

String:

#### Example:

     StringUtil.toSentence("liveDown_by-the.River");
     // 'live down by the river'

     StringUtil.toSentence("liveDown_by-the.River", '-');
     // 'live-down-by-the-river'

     StringUtil.toSentence("liveDown_by-the.River", '_');
     // 'live_down_by_the_river'

     StringUtil.toSentence("liveDown_by-the.River", '/');
     // 'live/down/by/the/river'

### `truncate`
(

- `text`
- `length`
- `indicator`

)
String public static

Defined in `js/util/StringUtil.js:213`

#### Parameters:

- `text` String
- `length` Int
- `indicator` String

#### Returns:

String:

#### Example:

      StringUtil.truncate('Robert is cool and he likes bruschetta.', 14));
      // 'Robert is cool...'
     StringUtil.truncate('Robert is cool and he likes bruschetta.', 14, '!!!'));
      // 'Robert is cool!!!'

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index