Skip to content

Instantly share code, notes, and snippets.

@rrrhys
Created August 24, 2018 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrrhys/fda77cc453020acd5b609d7c48a7b930 to your computer and use it in GitHub Desktop.
Save rrrhys/fda77cc453020acd5b609d7c48a7b930 to your computer and use it in GitHub Desktop.
Add tabstops to a body of text (React Native *does not* render tabs.
private repairBrokenTabs(text: string) {
let newLine = "\n";
let textLines = text.split(newLine);
let tabStop = 10;
let spaceString = Array(tabStop+1).join(" "); //
for (let l = 0; l < textLines.length; l++) {
let line = textLines[l];
while (line.indexOf("\t") > -1) {
let tabPos = line.indexOf("\t");
let modulo = tabStop - (tabPos % tabStop);
if (modulo === 0) {
modulo = tabStop;
}
line = line.replace("\t", spaceString.substr(0, modulo));
}
textLines[l] = line;
}
text = textLines.join(newLine);
return text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment