Wrap

Wraps a string at the specified limit, breaking at the last space within the limit.

Method Signature

Wrap(string=[string], limit=[integer], strip=[boolean])

Arguments

Argument
Type
Required
Description
Default

string

string

true

The string to wrap.

limit

integer

true

The character limit at which to wrap the string.

strip

boolean

false

If true, replaces all line endings with spaces before wrapping. Default is false.

false

Examples

Script Syntax

Run Example

sentence = "This is a standard sentence.";
wrappedSentence = wrap( sentence, 7 );
writeOutput( wrappedSentence );

Result: This is a standar d senten ce.

Tag Syntax

<bx:set sentence = "This is a standard sentence." >
<bx:set wrappedSentence = wrap( sentence, 7 ) >
<bx:output>#wrappedSentence#</bx:output>

Result: This is a standar d senten ce.

Additional Examples

Run Example

long_string = "A light-weight dynamic scripting language for the JVM that enables the rapid development of simple to highly sophisticated web applications.";
echo( "<pre>" & wrap( long_string, 20 ) & "</pre>" );

Last updated

Was this helpful?