Removing special characters from strings, and replacig fixes

This commit is contained in:
MrFry 2019-10-07 09:54:46 +02:00
parent b647007337
commit 5b8ee3fbb8

20
main.js
View file

@ -83,7 +83,7 @@ class StringUtils {
var toremove = this.NormalizeSpaces(val) var toremove = this.NormalizeSpaces(val)
var regex = new RegExp(char, 'g') var regex = new RegExp(char, 'g')
toremove.replace(regex, ' ') toremove = toremove.replace(regex, ' ')
return this.RemoveUnnecesarySpaces(toremove) return this.RemoveUnnecesarySpaces(toremove)
} }
@ -107,11 +107,21 @@ class StringUtils {
var removableChars = [',', '.', ':', '!'] var removableChars = [',', '.', ':', '!']
for (var i = 0; i < removableChars.length; i++) { for (var i = 0; i < removableChars.length; i++) {
var regex = new RegExp(removableChars[i], 'g') var regex = new RegExp(removableChars[i], 'g')
value.replace(regex, '') value = value.replace(regex, '')
} }
return value return value
} }
RemoveSpecialChars (value) {
assert(value)
let removableChars = ['&']
return removableChars.reduce((res, x) => {
let regex = new RegExp(x, 'g')
return res.replace(regex, '')
}, value)
}
// if the value is empty, or whitespace // if the value is empty, or whitespace
EmptyOrWhiteSpace (value) { EmptyOrWhiteSpace (value) {
// replaces /n-s with "". then replaces spaces with "". if it equals "", then its empty, or only consists of white space // replaces /n-s with "". then replaces spaces with "". if it equals "", then its empty, or only consists of white space
@ -146,9 +156,9 @@ class StringUtils {
class Question { class Question {
constructor (q, a, i) { constructor (q, a, i) {
this.Q = q this.Q = SUtils.RemoveSpecialChars(q)
this.A = a this.A = SUtils.RemoveSpecialChars(a)
this.I = i this.I = SUtils.RemoveSpecialChars(i)
} }
toString () { toString () {