How to substring method in React native? I tried all methods which are given below but none of the method worked.
substring, slice, substr
How to substring method in React native? I tried all methods which are given below but none of the method worked.
substring, slice, substr
The substring method is applied to a string object.
The substring() method extracts the characters from a string, between two specified indices, and returns the new substring.
This method extracts the characters in a string between "start" and "end", not including "end" itself.
If "start" is greater than "end", this method will swap the two arguments, meaning str.substring(1, 4) == str.substring(4, 1).
If either "start" or "end" is less than 0, it is treated as if it were 0.
Note: The substring() method does not change the original string.
The way to use it is this:
var str = "Hello world!";
var res = str.substring(1, 4);
// res value is "ell"
try
(obj.str).substring(1, 4);
Another alternative, you can make simple function. and then print in your jsx.
var number = "62857123456"
const slice = {
phone: (input: string = '') => {
let output = '';
// you can use substring, slice, substr
output = input.slice(2,14);
return output;
},
};
Finally, print on your jsx by calling the function that was created.
{slice.phone(number)}
I have faced the same situation For this the solution is place all js code in a function and call it externally
class AboutMe extends Component {
displayAboutMe(){
var data = this.props.getAboutMeQuery;
if(data.loading){
return(<div>Loading Books</div>)
}else{
var aboutMe = JSON.stringify(this.props.getAboutMeQuery.aboutme);
console.log(aboutMe);
var res = aboutMe.substring(12,453);
console.log(res);
}
}
render(){
this.displayAboutMe()
return (
<div id="profile-section"></div>
)}}