Extracts a random substring from the provided content string.

Selects two random positions within the content and returns the substring between them. The starting position is always before the ending position. Automatically trims whitespace from the beginning and end of the result. Useful for creating excerpts, search terms, or partial content samples.

  const text = "The quick brown fox jumps over the lazy dog";

RandomGenerator.substring(text); // "quick brown fox"
RandomGenerator.substring(text); // "jumps over"
RandomGenerator.substring(text); // "fox jumps over the lazy"

// Generate search terms from content
const searchQuery = RandomGenerator.substring(articleContent);

// Create excerpts for previews
const excerpt = RandomGenerator.substring(fullBlogPost);

// Generate partial matches for testing search functionality
const partialMatch = RandomGenerator.substring(productDescription);

// Create random selections for highlight testing
const selectedText = RandomGenerator.substring(documentContent);
  • Parameters

    • content: string

      The source string to extract a substring from

    Returns string

    A trimmed substring of the original content