正如标题所提到的,我正在尝试找到一种省略字符串数组的方法。我首先考虑使用 ellipsizeMode
属性中的 tail
和 head
属性,但它说我一次只能使用一个。知道怎么做吗?
最佳答案
如果您知道字符数限制
render(){
const maxLimit=38 //for example
const myText=arrayString.join(" ");
return(
<Text>
{myText.length > maxLimit
? '...' +
myText.substring(
myText.length / 2 - maxLimit / 2,
myText.length / 2 + maxLimit / 2,
) + '...'
: myText}
</Text>
);
}
关于javascript - 省略字符串前后的文本 [React Native],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59164488/