Difference between revisions of "delimiter-prefixed string"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search
(revision to match new title)
 
(One intermediate revision by the same user not shown)
Line 4: Line 4:
 
</hide>
 
</hide>
 
==About==
 
==About==
In coding, a [[segmented string]] is a string value that contains multiple substrings of variable length divided by a specific character.
+
In coding, a [[delimiter-prefixed string]] is a string value that contains single-character-delimited substrings of variable length where the delimiting character is always included as the first character of the string.
  
This is the most generally useful when the dividing character is defined as the first character in the string, so that the dividing character does not have to be set or passed separately. This makes it possible to store lists of short strings as a single value. The only constraint this adds is that the dividing character must not appear in any of the substrings; this technique is therefore most useful for predefined constants, where a dividing character can be chosen that won't conflict with the substring values and hopefully will help to visually set the values apart.
+
This eliminates the need to define or pass the delimiting character separately, which makes it easy to store lists of short strings as a single value. The only constraint this adds is that the delimiting character must not appear in any of the substrings; this technique is therefore most useful for predefined constants, where a character can be chosen that won't conflict with the substring values and hopefully will help to visually set the values apart.
  
 
Examples:
 
Examples:
 
* <code>"/one/two/three/four"</code> (dividing char = "/")
 
* <code>"/one/two/three/four"</code> (dividing char = "/")
 
* <code>" Monday Tuesday Wednesday Thursday Friday Saturday Sunday"</code> (dividing char = space)
 
* <code>" Monday Tuesday Wednesday Thursday Friday Saturday Sunday"</code> (dividing char = space)

Latest revision as of 23:11, 28 September 2019

About

In coding, a delimiter-prefixed string is a string value that contains single-character-delimited substrings of variable length where the delimiting character is always included as the first character of the string.

This eliminates the need to define or pass the delimiting character separately, which makes it easy to store lists of short strings as a single value. The only constraint this adds is that the delimiting character must not appear in any of the substrings; this technique is therefore most useful for predefined constants, where a character can be chosen that won't conflict with the substring values and hopefully will help to visually set the values apart.

Examples:

  • "/one/two/three/four" (dividing char = "/")
  • " Monday Tuesday Wednesday Thursday Friday Saturday Sunday" (dividing char = space)