From 5b8ee3fbb8225fb9a11800ae904deed40cad1c92 Mon Sep 17 00:00:00 2001 From: MrFry Date: Mon, 7 Oct 2019 09:54:46 +0200 Subject: [PATCH] Removing special characters from strings, and replacig fixes --- main.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index 59e08f6..913297a 100644 --- a/main.js +++ b/main.js @@ -83,7 +83,7 @@ class StringUtils { var toremove = this.NormalizeSpaces(val) var regex = new RegExp(char, 'g') - toremove.replace(regex, ' ') + toremove = toremove.replace(regex, ' ') return this.RemoveUnnecesarySpaces(toremove) } @@ -107,11 +107,21 @@ class StringUtils { var removableChars = [',', '.', ':', '!'] for (var i = 0; i < removableChars.length; i++) { var regex = new RegExp(removableChars[i], 'g') - value.replace(regex, '') + value = value.replace(regex, '') } 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 EmptyOrWhiteSpace (value) { // 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 { constructor (q, a, i) { - this.Q = q - this.A = a - this.I = i + this.Q = SUtils.RemoveSpecialChars(q) + this.A = SUtils.RemoveSpecialChars(a) + this.I = SUtils.RemoveSpecialChars(i) } toString () {