I'm currently developing theme for Textual IRC and I want to compare the "Topic is ..." messages to the topic displayed in the channels topic bar, to delete them if the are the same.
The topic that causes problems has both Umlaute and a URI in it and looks like the following:
++ Frische Austern ++ Nächste Sitzung: https:/some/uri/that/can/contain/umlaute" ++
When I print both the old topic and the new topic, they look exactly the same, down to the trailing and leading whitespaces (I used trim()
to eliminate them).
The comparison is done with
if(oldTopic === newTopic){
// do stuff
}
I used typeof
to make sure both them are of the type string and not Object
I used replace(/ä/g, 'ae')
to eliminate the Umlaute
I used replace(/\//g, '_')
to get rid of the forward slashes
I used escape()
to escape non unicode characters
Unfortunately none of it worked. Again if I use console.log
to show the two strings, they are exactly the same. I was expecting some Unicode stuff, that you can represent ä in different ways, but replacing it didn't work either.
I've tried but I reached my limit of my JavaScript knowledge. I have really no idea why it's not working. The code has worked on some other topics, that did neither involve any Umlaute nor an URL.
If any of you happens to know an answer I'd be very thankful.
Kind regards and thanks in advance!
So in the end the whitespace right before the https
part was a different type of whitespace, than all the others.
It was not a tab and I tried different regular expression symbols to get it (\f
, \r
and stuff) but it didn't work out.
What worked in the end was using replace(/\s/g, '')
. \s
also covers tabs, but I assume, that there probably won't be a topic change, that has no other change, than changing a whitespace to a tab.
Just keep in mind, that if tabs and whitespaces have to make a difference in your case, this solution won't work.