2

I'm using some code that seems to require that I make an array that uses the tilde (~) symbol, as below:

var quizArray = [
'27~29~Which sentence is written correctly?~Julie said "I have an older brother named Ike."~Mrs. Wagner, said "Children, return to your seats."~Mario looked at me and said, "I don\'t believe it!"~"I can\'t remember his address" admitted, Zach.'
];

Why use the tilde instead of a comma? Is this part of proprietary code scheme?

Sled
  • 18,541
  • 27
  • 119
  • 168
Stephen V
  • 29
  • 2
  • 1
    That's just an array containing a string an index 0 -- http://jsfiddle.net/uB2Rq/ – tymeJV Jul 22 '13 at 20:22
  • 1
    My guess is whoever wrote this didn't want to have to think about escaping out common delimiters, so they just use an uncommon character as the delimiter. It's likely they also restricted the text so that tildes are not valid inside the actual data. It could be laziness, or it could be that the parser that they are using just can't handle more complex string splits. The tilde itself is nothing more than a delimiter that will be used somewhere else while parsing this string, and doesn't mean anything technical here. – Joe Enos Jul 22 '13 at 20:23
  • 1
    that's just an arbitrary data separator, probably treating that string as a tilde-separated-value, using tildes instead of commas... which you'd recognize as "CSV". That's nothing to do with javascript. – Marc B Jul 22 '13 at 20:23

3 Answers3

2

That's an array with a single element. (Note the single quotes around the entire string.) The tildes are probably used as delimiters to parse the string somewhere later in the processing.

The reason for not using a comma as a separator is that the data itself contains commas. Personally, I would have used a special character (perhaps \t, or \u0000) instead of a tilde as a delimiter—something that never should appear in normal text.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
1

That's a single string. The only reason tilde is used is later it is split into array of strings and tilde is used as a separator. Comma cannot be used, because it is a part of inner string (used in a sentence)

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136
0

Perhaps the tildes are being used as an explode delimiter somewhere?

Collin Henderson
  • 1,154
  • 10
  • 22