File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed
snippets/python/string-manipulation Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
title : Truncate String
3
- description : Truncates a string to a specified length and adds a toggleable ellipsis .
3
+ description : Truncates a string to a specified length and a toggleable truncation notation .
4
4
author : axorax
5
5
contributors : MinerMinerMods
6
6
tags : string,truncate
7
7
---
8
8
9
9
``` py
10
10
def truncate (s :str , length :int , suffix :bool = True ) -> str :
11
- return (s[:length] + (" … " if suffix else " " )) if len (s) > length else s
11
+ return (s[:length] + (" ... " if suffix else " " )) if len (s) > length else s
12
12
13
13
# Usage:
14
- truncate(' This is a long string' , 10 ) # Returns: 'This is a … '
14
+ truncate(' This is a long string' , 10 ) # Returns: 'This is a ... '
15
15
truncate(' This is a long string' , 10 , False ) # Returns: 'This is a '
16
16
```
You can’t perform that action at this time.
0 commit comments