This seems reasonably straight forward to implement in your own code base:

```
def truncate(string, length, padding \\ ".") do
  string
  |> String.slice(0, length)
  |> String.pad_trailing(String.length(string), padding)
end
```

Not seeing a strong need to include it in the standard library. Just my 
$0.02
On Saturday, November 19, 2022 at 2:12:19 PM UTC-5 Kip wrote:

> That is comes from Laravel, not PHP core may be an indication it is better 
> implemented in a library?  If there is momentum towards adding it to the 
> String module I think `String.truncate` would feel more natural to me (its 
> also what Ruby uses).  
>
> Its difficult to make guarantees about the printable width though since 
> characters like ZWJ and Bidi text would mean that to do this properly is 
> not a simple or straight forward situation.  For that reason I don't 
> personally think it belongs in Elixir itself.
>
> On Saturday, November 19, 2022 at 5:20:21 PM UTC+1 hassanr...@gmail.com 
> wrote:
>
>> Hi all,
>> I came across from laravel <https://laravel.com> framework, where there 
>> are a lot of useful functions, I miss those functions in Elixir, One of the 
>> functions is called limit 
>> <https://laravel.com/docs/9.x/helpers#method-str-limit> function, I 
>> would like to have that in elixir.
>> ```
>> iex> String.limit("elixir", 3)
>> "eli..."
>>
>> iex> String.limit("elixir", 7)
>> "elixir"
>>
>> iex> String.limit("elixir", 3, "***")
>> "eli***"
>> ```
>> This function would be really helpful with longer string, we can limit 
>> long string with some trailing string like (...).
>>
>> What do you think? If yes what should be the name you suggest?
>>
>> Thanks,
>> Hassan
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/35628c34-c8c4-4558-a985-de87ec7111d3n%40googlegroups.com.

Reply via email to