forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbetween.as
More file actions
34 lines (26 loc) · 928 Bytes
/
between.as
File metadata and controls
34 lines (26 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package utils.string {
/**
* Returns everything after the first occurrence of begin and before the first occurrence of end in String.
* @param value Input String
* @param start Character or sub-string to use as the start index
* @param end Character or sub-string to use as the end index
* @returns Everything after the first occurrence of begin and before the first occurrence of end in String.
* @author Aaron Clinger
* @author Shane McCartney
* @author David Nelson
*/
public function between(value:String, start:String, end:String):String {
var out:String = "";
if(value) {
var startIdx:int = value.indexOf(start);
if(startIdx != -1) {
startIdx += start.length; // RM: should we support multiple chars? (or ++startIdx);
var endIdx:int = value.indexOf(end, startIdx);
if(endIdx != -1) {
out = value.substr(startIdx, endIdx - startIdx);
}
}
}
return out;
}
}