File: count-substring.2gg

package info (click to toggle)
golf 601.4.41-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,824 kB
  • sloc: ansic: 20,020; sh: 1,171; makefile: 292
file content (58 lines) | stat: -rw-r--r-- 1,456 bytes parent folder | download
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
.TH GOLF 2gg $VERSION $DATE Development Tools
.SH NAME
count-substring \-  (strings)
.SH PURPOSE
Count substrings.

.SH SYNTAX

.RS 4
.EX

count-substring <substring> in <string> to <count> [ case-insensitive [ <case insensitive> ] ]

.EE
.RE

.SH DESCRIPTION
count-substring counts the number of occurrences of <substring> in <string> and stores the result in <count> (specified in "to" clause). By default, search is case-sensitive. If you use "case-insensitive" clause without boolean variable <case insensitive>, or if <case insensitive> evaluates to true, then the search is case-insensitive.

If <substring> is empty (""), <count> is 0.

.SH EXAMPLES
In the following example, 1 occurrence will be found after the first count-substring, and 2 after the second (since case insensitive search is used there):

.RS 4
.EX

set-string sub = "world"
set-string str = "Hello world and hello World!"

count-substring sub in str to num_occ
print-format "Found %ld occurrences!\en", num_occ

count-substring sub in str to num_occ case-insensitive
print-format "Found %ld occurrences!\en", num_occ

.EE
.RE

.SH SEE ALSO
 Strings

\fBconcatenate-strings\fP  
\fBcopy-string\fP  
\fBcount-substring\fP  
\fBdelete-string\fP  
\fBlower-string\fP  
\fBnew-string\fP  
\fBread-split\fP  
\fBreplace-string\fP  
\fBset-string\fP  
\fBsplit-string\fP  
\fBstring-length\fP  
\fBtrim-string\fP  
\fBupper-string\fP  
\fBwrite-string\fP   
See all 
\fBdocumentation\fP