Skip to content

ProtoString wrap() Method

Seth Clydesdale edited this page May 29, 2015 · 1 revision

<< Back to Miscellaneous Methods

Examples

Wrapping a string with two other strings.

'JavaScript'.wrap('[', ']'); // returns '[JavaScript]'

'Chapter 1'.wrap('<h3>', '</h3>'); // returns '<h3>Chapter 1</h3>'

'coffee'.wrap('Let\'s have ', ' later.'); // returns 'Let's have coffee later.'

You can also pass along only a single string. If it's a tag, corrections will be made to the end string.

'Quote'.wrap('"'); // returns '"Quote"'

'Black Coffee'.wrap('<strong>'); // returns '<strong>Black Coffee</strong>'

'Title'.wrap('<h1 class="title">'); // returns '<h1 class="title">Title</h1>'

'Important'.wrap('[b]'); // returns '[b]Important[/b]'

Description

The wrap method is used to wrap a text string with two other strings. It simply concats the strings to the beginning and end. If a tag is passed ( HTML, BB ) and unclosed, a condition is set in place to make corrections to close it.

Syntax

String.wrap(alpha, omega);

Parameters

Parameter Description
alpha A string containing the content you want placed at the beginning of the string. Defaults to '<p>' if left undefined.
omega A string containing the content you want placed at the end of the string. Defaults to alpha if left undefined.
Clone this wiki locally