Created
August 24, 2018 05:54
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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