Gidsss / UwUIDE

A compiler made to be cute uwu >~<
6 stars 0 forks source link

"getting substrings" builtin methods for String #246

Closed am-cid closed 4 months ago

am-cid commented 4 months ago
  1. first() takes in int, gets from the 0th char up to n.
    
    a-senpai = "01234"~
    pwint(a.first(2))~
    >.< output: "01"

pwint(a.first(0))~

.< output: ""

pwint(a.first(999))~

.< output: "01234"

pwint(a.first(-1))~

.< output: "" .< negative numbers are floored to 0


2. `last()` takes in int, gets last char up to n
```python
a-senpai = "01234"~
pwint(a.last(2))~
.< output: "34"

pwint(a.last(0))~

.< output: ""

pwint(a.last(999))~

.< output: "01234"

pwint(a.last(-1))~

.< output: "" .< negative numbers are floored to 0


3. `substr()` takes two ints (n,m), gets from nth char up to mth char
```python
a-senpai = "01234"~
pwint(a.substr(0,2))~
.< output: "012"

pwint(a.substr(0,0))~

.< output: "" pwint(a.substr(999,0))~ .< output: "" .< if n >= m, it will return ""

pwint(a.substr(0,999))~

.< output: "01234"

pwint(a.last(-1, 2))~

.< output: "012" .< negative numbers are floored to 0


4. `from()` takes str (item), returns empty string if item is not in string. returns substring containing item up to end of the string
```python
a-senpai = "01234"~
pwint(a.from("2"))~
.< output: "234"

pwint(a.from("5"))~

.< output: ""

pwint(a.from("34"))~

.< output: "34"


5. `upTo()` takes str (item), returns empty string if item is not in string. returns substring containing beginning of string up to item
```python
a-senpai = "01234"~
pwint(a.upTo("2"))~
.< output: "012"

pwint(a.upTo("5"))~

.< output: ""

pwint(a.upTo("12"))~

.< output: "012"