> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/d/determine_if_a_string_is_squeezable.md).

# Determine if a string is squeezable

```ruby
func squeeze(str, c) {
    str.gsub(Regex("(" + c.escape + ")" + '\1+'), {|s1| s1 })
}
 
var strings = ["",
        '"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ',
        "..1111111111111111111111111111111111111111111111111111111111111117777888",
        "I never give 'em hell, I just tell the truth, and they think it's hell. ",
        "                                                   ---  Harry S Truman  ",
        "😍😀🙌💃😍😍😍🙌"]
 
var squeeze_these = ["", "-", "7", ".", " -r", "😍"]
 
[strings, squeeze_these].zip {|str,st|
    say "    original: «««#{str}»»» (length: #{str.len})"
    st.each {|c|
        var ssq = squeeze(str, c)
        say "'#{c}'-squeezed: «««#{ssq}»»» (length: #{ssq.len})"
    }
    say ''
}
```

#### Output:

```
    original: «««»»» (length: 0)

    original: «««"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln »»» (length: 72)
'-'-squeezed: «««"If I were two-faced, would I be wearing this one?" - Abraham Lincoln »»» (length: 70)

    original: «««..1111111111111111111111111111111111111111111111111111111111111117777888»»» (length: 72)
'7'-squeezed: «««..1111111111111111111111111111111111111111111111111111111111111117888»»» (length: 69)

    original: «««I never give 'em hell, I just tell the truth, and they think it's hell. »»» (length: 72)
'.'-squeezed: «««I never give 'em hell, I just tell the truth, and they think it's hell. »»» (length: 72)

    original: «««                                                   ---  Harry S Truman  »»» (length: 72)
' '-squeezed: ««« --- Harry S Truman »»» (length: 20)
'-'-squeezed: «««                                                   -  Harry S Truman  »»» (length: 70)
'r'-squeezed: «««                                                   ---  Hary S Truman  »»» (length: 71)

    original: «««😍😀🙌💃😍😍😍🙌»»» (length: 8)
'😍'-squeezed: «««😍😀🙌💃😍🙌»»» (length: 6)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://trizen.gitbook.io/sidef-lang/programming_tasks/d/determine_if_a_string_is_squeezable.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
