Skip to content

Instantly share code, notes, and snippets.

@pranavrajs
Created December 19, 2016 14:09
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pranavrajs/66bccee3f8ba100742a1273db6f587af to your computer and use it in GitHub Desktop.
Save pranavrajs/66bccee3f8ba100742a1273db6f587af to your computer and use it in GitHub Desktop.
React-Native Escape Character
function escapeCharAndroid(url, body) {
return fetch(url, { // Use your url here
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(body)
})
.then(response => response.text()) // Convert to text instead of res.json()
.then((text) => {
if (Platform.OS === 'android') {
text = text.replace(/\r?\n/g, '').replace(/[\u0080-\uFFFF]/g, ''); // If android , I've removed unwanted chars.
}
return text;
})
.then(response => JSON.parse(response)); // Parse the text.
}
@pranavrajs
Copy link
Author

pranavrajs commented Sep 1, 2020

@michaelcv Glad, it helped, but I honestly don't remember what it does. 😄 However, I remember it was something related to encoding issues in ASP webservers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment