My C# Spintax Function

imageek

Newbie
Joined
Apr 14, 2013
Messages
15
Reaction score
6
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.
 
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.


thank you for this good share mate. Cheers.
Simple and effective indeed, this might help me with some of my projects. :)
 
This is freaking awesome! Been using this on my bots, works very well. :) Bumping so others can see it too.
 
Back
Top