JSFiddle - React, Tailwind, and code Playground

by cse330

HTML

<pre id="outPre"></pre>

JavaScript

// Trim whitespace from begining and end:
var trimmed = Ext.String.trim("  Hello World ");

// Format a string by passing arguments (similar to sprintf):
var formatted = Ext.String.format("We need {0} and {1} today",
                                  "Apples",
                                  "Bananas");

// Limit the string length to 20 characters:
var ellipsis = Ext.String.ellipsis("Lorem ipsum dolor sit amet", 20);

// Capitalize the first character of the string:
var capitalized = Ext.String.capitalize("hello world");

// Pad a number or string with zeros to make it 4 characters long:
var padded = Ext.String.leftPad(35, 4, "0");

// Repeat a string multiple times:
var repeated = Ext.String.repeat("-", 20);

// * * * * * * * * *
// Display our results
Ext.fly("outPre").createChild(Ext.String.format("trimmed: \"{0}\"\n", trimmed));
Ext.fly("outPre").createChild(Ext.String.format("formatted: \"{0}\"\n", formatted));
Ext.fly("outPre").createChild(Ext.String.format("ellipsis: \"{0}\"\n", ellipsis));
Ext.fly("outPre").createChild(Ext.String.format("capitalized: \"{0}\"\n", capitalized));
Ext.fly("outPre").createChild(Ext.String.format("padded: \"{0}\"\n", padded));
Ext.fly("outPre").createChild(Ext.String.format("repeated: \"{0}\"\n", repeated));