Jump to content

User:Modbear/Sandbox

From Wikipedia, the free encyclopedia


A counterstring is a specifically graduated string that self-documents its length. These strings consist of alternating numbers and delimiter characters (usually asterisks), at that each number specifies the position of the immediately following delimiter character. This pattern makes is easy to determine the string length or the position of a specific character without actually counting characters in the string.[1]

Following is a 20-character long counterstring:

2*4*6*8*11*14*17*20*

Here, the asterisk following the number 20 is the twentieth character in the string, the one following the number 17 is the seventeenth, and so on. Knowing the asterisk positions, it is also easy to tell that 0 of 20 is at position 19, 1 of 17 is at position 15, and so on.

Counterstring types

[edit]

Counterstrings can be generated either forward or backward. Forward counterstrings are generated from left to right, starting with the number 2, whereas backwards are filled from right to left starting with the delimiter character.

Forward and backward counterstrings of certain lengths differ. For example, below are 21-character long forward and backward counterstrings, respectively:

2*4*6*8*11*14*17*20*2
*3*5*7*9*12*15*18*21*

The forward counterstring generation is more suitable when the string is being immediately written to a file, as it does not have to be buffered. In other cases, backward counterstrings are preferable to forward ones. This is due to the fact that the last character of backward counterstrings is the delimiter character (which is not necessarily in forward counterstrings), so the string length is more obvious.[2]

Uses

[edit]

Counterstrings are usually used in software testing to determine the length of text input fields in an application. This is done by pasting a too long counterstring into the field and examining the truncated string.[1][2][3]

References

[edit]
  1. ^ a b James Bach (2004-06-22). "Counterstrings: Self-Describing Test Data". Retrieved 2009-03-30.
  2. ^ a b "Test Utilities in Excel". Retrieved 2009-03-30.
  3. ^ Christopher Miller (2005-11-28). "Counterstrings". Retrieved 2009-03-30.