-
-
Save rrreese/6814480 to your computer and use it in GitHub Desktop.
Scite Word Count
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
--Calculate whitespace control | |
for m in editor:match("\n") do --count newline | |
whiteSpace = whiteSpace + 1; | |
end | |
for m in editor:match("\r") do --count carriage return | |
whiteSpace = whiteSpace + 1; | |
end | |
for m in editor:match("\t") do --count tabs | |
whiteSpace = whiteSpace + 1; | |
end |
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
--calculate number of words | |
local itt = 0; | |
while itt < editor.LineCount do --iterate through each line | |
line = editor:GetLine(itt); | |
if line then | |
for word in string.gfind(line, "%w+") do | |
wordCount = wordCount + 1 | |
end | |
end | |
itt = itt + 1; | |
end |
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
--Calculate non-empty lines | |
local itt = 0; | |
while itt < editor.LineCount do --iterate through each line | |
local hasChar, hasNum = 0; | |
line = editor:GetLine(itt); | |
if line then | |
hasAlphaNum = string.find(line,'%w'); | |
end | |
if (hasAlphaNum ~= nill) | |
nonEmptyLine = nonEmptyLine + 1; | |
end | |
itt = itt + 1; | |
end |
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
print("----------------------------"); | |
print("Char Count: \t",editor.Length); | |
print("Word Count: ",wordCount); | |
print("Line Count: \t",editor.LineCount); | |
print("Non empty lines: ", nonEmptyLine); | |
print("Empty lines: \t", editor.LineCount - nonEmptyLine); | |
print("White Space: \t", whiteSpace); | |
print("Non white space chars: ",(editor.Length)-whiteSpace); | |
print("Current Pos: ",editor.CurrentPos); | |
print("Current Line: ", | |
editor:LineFromPosition(editor.CurrentPos) +1); |
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
local newline = 0; --number of newlines | |
local nonEmptyLine = 0; --number of non blank lines | |
local wordCount = 0; --total number of words | |
local whiteSpace = 0; --number of whitespace chars |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment