0

I'm getting HTML content from a JSON file. The JSON file returns attributes name and description.

The name is clean data, like "Cheese burger". But the description looks like this ["Mozarella","Pepperoni","Cheese","Beef","Ketchup"].

Is it possible to tell CSS not to display the special characters: [",

Is it possible to filter out the special characters with javascript / AngularJS?

3 Answers 3

2

You can use replace() with regexp to replace special characters type by type :

var descriptionString = '["Mozarella","Pepperoni","Cheese","Beef","Ketchup"]';

var cleanBracketsLeft = descriptionString.replace(/\[/g, '');
var cleanBracketsRight = cleanBracketsLeft.replace(/\]/g, '');
var cleanQuotes = cleanBracketsRight.replace(/\"/g, '');
var cleanComma = cleanQuotes.replace(/\,/g, ' ');

console.log(cleanComma);
//Result Mozarella Pepperoni Cheese Beef Ketchup

See live exemple

See also a Regular Expression tutorial

Sign up to request clarification or add additional context in comments.

Comments

1

I believe this cannot be done with pure CSS - and even if it can it is bad practice. CSS is about appearence. You need some logic there.

So javascript is the way to go. And my opinion is not to use any custom libraries, as it is mentioned in previous answers, but spend some time studying regular expressions. You ll eventually see that they are extremely usefull. You need a fairly simple one to just remove ]",

Comments

0

You can not hide special characters in CSS. With javascript, you can use a lib like: https://github.com/andrewrk/node-diacritics to remove all special characters from your texts.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.