1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

My C# Spintax Function

Discussion in 'C, C++, C#' started by imageek, Aug 14, 2014.

  1. imageek

    imageek Newbie

    Joined:
    Apr 14, 2013
    Messages:
    15
    Likes Received:
    4
    Occupation:
    Self Employed Software Developer and Marketer
    Location:
    United Kingdom
    I developed this function years ago, and it's never faulted me to this day. I use it in most of my applications - usually to spin content, and avoid spam traps.

    I could have coded a simple spintax parser and released it free, but thought I'd release the code instead. Many people may find this useful.

    Code:
    /**
    * Coded by: James Jeffery <imageek{at}live.com>
    **
    * I'm saving for IVF treatment. If you like my work feel free to donate $1 to Paypal <imageek{at}live.com> :D
    **/
    
    public String parseSpintax(Random rand, String s)
    {
             if(s.Contains('{')) {
                int closingBracePosition = s.IndexOf('}');
                int openingBracePosition = closingBracePosition;
                while(!s[openingBracePosition].Equals('{')) openingBracePosition--;
                String spintaxBlock = s.Substring(openingBracePosition, closingBracePosition - openingBracePosition + 1);
                String[] items = spintaxBlock.Substring(1, spintaxBlock.Length - 2).Split('|');
                s = s.Replace(spintaxBlock, items[rand.Next(items.Length)]);
                return parseSpintax(rand, s);
            } else { return s; }
    }
    
    Use it as you wish. I have created a class that can do other neat stuff with the spintax, and tokens. But I'm not giving that up :p

    Once implemented call it like this:

    Code:
    String username = "{{Sexy|Hot|XXX|Love}{Babe|Hot|Hottie|Baby}{1|2|3|4|5|6|7|8|9|0}{1|2|3|4|5|6|7|8|9|0}}";
    Random rand = new Random();
    
    String parsed1 = parseSpintax(rand, username);
    String parsed2 = parseSpintax(rand, username);
    String parsed3 = parseSpintax(rand, username);
    
    // Output is random
    // parsed1 = SexyHot49
    // parsed2 = HotHottie11
    // parsed3 = LoveBaby49
    
    
    You can nest as many layers deep as you need. No limits. Nest 1000 times, it'll still work. You can easily convert the code to PHP, Javascript, VB etc.

    Enjoy.
     
    • Thanks Thanks x 3
  2. mihai1497

    mihai1497 Jr. VIP Jr. VIP Premium Member

    Joined:
    Jul 22, 2013
    Messages:
    490
    Likes Received:
    82
    This is simple and effective, thanks!
     
  3. member8200

    member8200 Regular Member

    Joined:
    Aug 9, 2014
    Messages:
    469
    Likes Received:
    33

    thank you for this good share mate. Cheers.
    Simple and effective indeed, this might help me with some of my projects. :)
     
  4. mnunes532

    mnunes532 Power Member

    Joined:
    Jan 21, 2014
    Messages:
    708
    Likes Received:
    178
    This is freaking awesome! Been using this on my bots, works very well. :) Bumping so others can see it too.
     
  5. Jack Preacher

    Jack Preacher Newbie

    Joined:
    Sep 6, 2016
    Messages:
    7
    Likes Received:
    2
    Gender:
    Male
    Sweet bit of code. Thanks! Adding it to my bag o' tricks :)