Valid commands for evaluate button:
number of <chunk> in [ <chunk> <number> [ to <number>] [ of ... ] of ] "<string>"
start of [ <chunk> <number> [ to <number>] [ of ... ] of ] "<string>"
end of [ <chunk> <number> [ to <number>] [ of ... ] of ] "<string>"
get [ <chunk> <number> [ to <number>] [ of ... ] of ] "<string>"
delete [ <chunk> <number> [ to <number>] [ of ... ] of ] "<string>"
put "<string>" into [ <chunk> <number> [ to <number>] [ of ... ] of ] "<string>"
put "<string>" before [ <chunk> <number> [ to <number>] [ of ... ] of ] "<string>"
put "<string>" after [ <chunk> <number> [ to <number>] [ of ... ] of ] "<string>"
Download the library: chunkex.js
Instructions for use:
cxl_count(text, tokens); text is, for example, "Apple Computer, Inc." tokens is an array, for example, ('chars', 'word', 2) result in this case would be 9 (number of CHARS in WORD 2 of ...) cxl_get(text, tokens); text is, for example, "Apple Computer, Inc." tokens is an array, for example, ('char', 3, 4, 'word', 2, 3) result in this case would be "mp" (get CHAR 3 to 4 of WORD 2 to 3 of ...) cxl_delete(text, tokens); text is, for example, "Apple Computer, Inc." tokens is an array, for example, ('char', 6, 8, 'word', 2) result in this case would be "Apple Compu, Inc." (delete CHAR 6 to 8 of WORD 2 of ...)
Get the idea?
cxl_start(text, tokens) returns the position of the first character of the chunk expression, starting from zero. cxl_end(text, tokens) returns the position of the last character of the chunk expression, starting from zero, plus one.
(These two are used with JavaScript's substring() method on strings.)
cxl_into(text, tokens, newtext) inserts newtext into (tokens) of text. cxl_before(text, tokens, newtext) inserts newtext before (tokens) of text. cxl_after(text, tokens, newtext) inserts newtext after (tokens) of text.
This:
text = cxl_delete(text, tokens);
DOES NOT do the same thing as this:
var s = cxl_start(text, tokens);
var e = cxl_end(text, tokens);
text = text.substring(0,s) + text.substring(e,text.length);
E.g., with text == "Apple Computer, Inc." and tokens == ('word', 2), the first method (cxl_delete) gives "Apple Inc.", and second method (substring) gives "Apple Inc.". Notice the extra space.