-
Couldn't load subscription status.
- Fork 0
ProtoString indent() Method
Seth Clydesdale edited this page Jun 10, 2015
·
1 revision
<< Back to Miscellaneous Methods
Indenting newlines with a tab.
'Coffee\nCream\nSugar'.indent();
/* returns
Coffee
Cream
Sugar
*/Passing a number as the first parameter will indent each newline n times.
'Coffee\nCream\nSugar'.indent(3);
/* returns
Coffee
Cream
Sugar
*/Passing a string as the second parameter allows you to redefine the indentation character.
'Coffee\nCream\nSugar'.indent(1, '• ');
/* returns
• Coffee
• Cream
• Sugar
*/The indent method can be used to indent the beginning of each newline with a tab. Passing a string as the second parameter will allow you to change the indentation character.
String.indent(amount, spacer);| Parameter | Description |
|---|---|
| amount | A number which represents the size of the indentation. Passing 3 will add 3 spaces to the beginning of each line. Defaults to 1. |
| spacer | A string which represents the indentation character. Defaults to a tab if left undefined. |
Home • History • ProtoString • Created by Seth Clydesdale