@@ -59,7 +59,13 @@ $result = $builder->buildSubstring(5);
59
59
fwrite(STDOUT, ' 3. Built substring ' . $result . PHP_EOL);
60
60
61
61
$result = $builder->charAt(5);
62
- fwrite(STDOUT, ' 4. Character ' . $result . PHP_EOL);
62
+ fwrite(STDOUT, ' 4. Character at position 5 ' . $result . PHP_EOL);
63
+
64
+ $result = $builder->firstChar();
65
+ fwrite(STDOUT, ' 5. First character ' . $result . PHP_EOL);
66
+
67
+ $result = $builder->lastChar();
68
+ fwrite(STDOUT, ' 6. Last character ' . $result . PHP_EOL);
63
69
```
64
70
65
71
will output the following
@@ -68,44 +74,46 @@ will output the following
68
74
1. Built string ä2wertzem ipsum dolor sit amet, conset
69
75
2. Built substring rt
70
76
3. Built substring rtzem ipsum dolor sit amet, conset
71
- 4. Character r
77
+ 4. Character at position 5 r
78
+ 5. First character ä
79
+ 6. Last character t
72
80
```
73
81
74
82
### Getting string properties
75
83
76
84
``` {php}
77
85
$result = $builder->length();
78
- fwrite(STDOUT, ' 5 . String length ' . $result . PHP_EOL);
86
+ fwrite(STDOUT, ' 7 . String length ' . $result . PHP_EOL);
79
87
80
88
$result = $builder->size();
81
- fwrite(STDOUT, ' 6 . Number of bytes ' . $result . PHP_EOL);
89
+ fwrite(STDOUT, ' 8 . Number of bytes ' . $result . PHP_EOL);
82
90
83
91
$result = $builder->indexOf('e');
84
- fwrite(STDOUT, ' 7 . First occurence of "e" ' . $result . PHP_EOL);
92
+ fwrite(STDOUT, ' 9 . First occurence of "e" ' . $result . PHP_EOL);
85
93
86
94
$result = $builder->indexOf('e', 5);
87
- fwrite(STDOUT, ' 8 . First occurence of "e" after position 5 ' . $result . PHP_EOL);
95
+ fwrite(STDOUT, '10 . First occurence of "e" after position 5 ' . $result . PHP_EOL);
88
96
89
97
$result = $builder->lastIndexOf('e');
90
- fwrite(STDOUT, ' 9 . Last occurence of "e" ' . $result . PHP_EOL);
98
+ fwrite(STDOUT, '11 . Last occurence of "e" ' . $result . PHP_EOL);
91
99
92
100
$result = $builder->lastIndexOf('e', 5);
93
- fwrite(STDOUT, '10 . Last occurence of "e" before the 5th last character ' . $result . PHP_EOL);
101
+ fwrite(STDOUT, '12 . Last occurence of "e" before the 5th last character ' . $result . PHP_EOL);
94
102
95
103
$result = $builder->contains('ipsum');
96
- fwrite(STDOUT, '12 . Whether the string contains "ipsum" ' . $result . PHP_EOL);
104
+ fwrite(STDOUT, '13 . Whether the string contains "ipsum" ' . $result . PHP_EOL);
97
105
```
98
106
99
107
will output the following
100
108
101
109
``` {txt}
102
- 5 . String length 38
103
- 6 . Number of bytes 39
104
- 7 . First occurence of "e" 4
105
- 8 . First occurence of "e" after position 5 8
106
- 9 . Last occurence of "e" 37
107
- 10 . Last occurence of "e" before the 5th last character 29
108
- 12 . Whether the string contains "ipsum" <TRUE>
110
+ 7 . String length 38
111
+ 8 . Number of bytes 39
112
+ 9 . First occurence of "e" 4
113
+ 10 . First occurence of "e" after position 5 8
114
+ 11 . Last occurence of "e" 37
115
+ 12 . Last occurence of "e" before the 5th last character 29
116
+ 13 . Whether the string contains "ipsum" <TRUE>
109
117
```
110
118
111
119
### Exception handling
0 commit comments