Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6772331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:32:14+00:00 2026-05-26T15:32:14+00:00

Spintax allows you to spin various words and sentences such as: {Hello|Hi} {World|People}! {C{#|++|}|Java}

  • 0

Spintax allows you to spin various words and sentences such as:

{Hello|Hi} {World|People}! {C{#|++|}|Java} is an {awesome|amazing} language.

The text between the braces would be selected at random to form different sentences.

I am able to possibly come up with a solution myself, but the problem I would have is the nesting. Sometimes the nesting can be very deep. What would be a possible solution to handling the nesting?

I can’t gather the logic needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:32:14+00:00Added an answer on May 26, 2026 at 3:32 pm

    Don’t worry about the nesting, just do it iteratively as follows:

    1. Find the first sequence in the string that has {...} with no other braces inside. For your case, that’s {Hello|Hi}. If there are no more of that pattern, go to step 3.

    2. Grab all the possibilities out of there and choose a random one, replacing the brace section with its value. Then go back to step 1.

    3. There’s your modified string.

    Let’s say you have a slightly faulty random number generator that always returns zero. Your string modification history would then be:

    a/ {Hello|Hi} {World|People}! {C{#|++|}|Java} is an {awesome|amazing} language.
    b/ Hello {World|People}! {C{#|++|}|Java} is an {awesome|amazing} language.
    c/ Hello World! {C{#|++|}|Java} is an {awesome|amazing} language.
    d/ Hello World! {C#|Java} is an {awesome|amazing} language.
    e/ Hello World! C# is an {awesome|amazing} language.
    f/ Hello World! C# is an awesome language.
    

    Note particularly the transition from (c) to (d). Because we’re looking for the first brace section that doesn’t have braces inside it, we do the {#|++|} before the {C{#|++|}|Java}.

    All you need to add now is the possibility that you may have {, } or | within your actual text – these will need to be escaped somehow to protect them from your modification engine.


    Here’s a little C# program which shows this in action. It’s probably not that impressively written, given my relative inexperience with the language, but it illustrates the process.

    using System;
    using System.Text.RegularExpressions;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static string spintax(Random rnd, string str) {
                // Loop over string until all patterns exhausted.
                string pattern = "{[^{}]*}";
                Match m = Regex.Match(str, pattern);
                while (m.Success) {
                    // Get random choice and replace pattern match.
                    string seg = str.Substring(m.Index + 1, m.Length - 2);
                    string[] choices = seg.Split('|');
                    str = str.Substring(0, m.Index) + choices[rnd.Next(choices.Length)] + str.Substring(m.Index + m.Length);
                    m = Regex.Match(str, pattern);
                }
    
                // Return the modified string.
                return str;
            }
    
            static void Main(string[] args) {
                Random rnd = new Random();
                string str = "{Hello|Hi} {World|People}! {C{#|++|}|Java} is an {awesome|amazing} language.";
                Console.WriteLine(spintax(rnd, str));
                Console.ReadLine();
            }
        }
    }
    

    The output is, in one example run

    Hello World! C# is an awesome language.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i think that i have a sintax error in this code <script type=text/javascript> $(document).ready(function()
I just finished a Java application to link to Sicstus prolog. Now I need
Does Geshi support the R programming language ? This table (Geshi for MediaWiki) does
When I saw this article about using a python-like sintax (indentation based, without curly
There is in operator in SQL SELECT * FROM MyTable WHERE id IN (1,
Say I have 2 objects MY_OBJ, MY_NESTED_TABLE_OBJ CREATE OR REPLACE TYPE MY_NESTED_TABLE_OBJ IS TABLE
i'm not sure to explain what i'm looking for. What's the name of the
I am a beginner in C# I wonder how to write in C# C's
I want to make a .bat to copy & rename a file multiple times.
I'm having problems with SQLite in Android. Eclipse does not report any error in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.