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

Article Spinnner

Discussion in 'C, C++, C#' started by mintuz, Jan 15, 2011.

  1. mintuz

    mintuz Newbie

    Joined:
    Jan 15, 2011
    Messages:
    42
    Likes Received:
    3
    Home Page:
    Hey I would like to produce a small article spinner. But not sure where to begin, I want the words inside the { } to be selected randomly by using the | bar and then output a spun text.

    Any ideas, kinda new to programming but I would love to learn how to do this if somebody can point me in the right direction.
     
  2. likeskoolaid

    likeskoolaid Regular Member

    Joined:
    Dec 27, 2009
    Messages:
    352
    Likes Received:
    104
    Occupation:
    \˚ㄥ˚\
    Location:
    \ᇂ_ᇂ\
  3. blakamia

    blakamia Junior Member

    Joined:
    Jan 25, 2010
    Messages:
    162
    Likes Received:
    343
    Here is program + source in C# for a simple one I wrote for you:
    (oops i cant post link. Here is source for the Spinner.cs class):

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace CustomRewriter
    {
        static class Spinner
        {
            static Random rand;
    
            public static string Spin(string rawText)
            {
                rand = new Random();
                StringBuilder sd = new StringBuilder();
    
                string[] split = rawText.Split(new string[1] { "{" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string s in split)
                {
                    string[] exitSpinSplit = s.Split(new string[1] { "}" }, StringSplitOptions.RemoveEmptyEntries);
                    StringBuilder sb = new StringBuilder();
                    foreach (string e in exitSpinSplit)
                    {
                        if (!e.Contains("|"))
                        {
                            sb.Append(e);
                        }
                        else
                        {
                            string[] splitSpin = e.Split(new string[1] { "|" }, StringSplitOptions.RemoveEmptyEntries);
                            sb.Append(splitSpin[GenerateRandomIndex(splitSpin.Length)]);
                        }
                    }
                    sd.Append(sb.ToString());
                }
                return sd.ToString();
            }
    
            private static int GenerateRandomIndex(int max)
            {
                int i = rand.Next(0, max);
                return i;
            }
        }
    }
    

    And here is some spintax to try out with it:
    Code:
    This {is|is actually|will be|can be|is usually|is definitely|is certainly|might be|is without a doubt|is normally|is going to be|is undoubtedly|is without question|may be|happens to be|is simply|could be|is in fact|is really|is almost certainly|is always|is considered to be|is truly|has been|is generally|is literally|is often|is considered|are|should be|has become|would be|is just|is now|is regarded as|definitely is|has always been|typically is|often is|is very much|could be described as|is also|'s|may|is ordinarily|was|is probably|can|must be|could very well be|could understood|recognized|comprehended|realized|grasped|perceived|fully understood|known|believed|appreciated|recognised|defined|seen|clear|thought of|wholly understood to be|to become|being|for being|to get|that they are|to generally be|to remain|that should be|to always be|turn out to be|as being|becoming|getting|that need be|as|grow to be|come to be|turn into|staying|to end up being|to stay|currently being|to work as|to become or stay|that needs to be|become|that you should|that can be|that will be|to|is|that must be|in order to|about being|that are|to have|develop into|to obtain|in order to become|that it is|you should be|in order to be|to acquire|of being|are|to be able to|for you to become|with regard to|for} {a|the|any|a new|some sort of|your|a good|an important|some|a fabulous|the latest|another|a good solid|a real|an absolute|an|one particular|each|a very|a suitable|one|an actual|any kind of|the right|your own|a complete|a particular|one specific|a nice|the perfect|the new|a meaningful|any kind of a|a functional|per|the best|a major|a single|a trustworthy|a definite|a huge|every|their|that|this|the particular|the actual|a great|that a|my cotton|100 % cotton|natural cotton|organic cotton|silk cotton|egyptian cotton|organic and natural|100 % organic cotton|organic|pure cotton|natural|natural and organic|healthy cotton|egyptian|cotton wool pad|mat|sleeping pad|sleep pad|station|cushion|topper|mattress pad|protect|bed|apartment} {simple|easy|basic|straightforward|uncomplicated|very simple|effortless|quick|hassle-free|straight forward|rather simple|relatively easy|simple and easy|painless|ordinary|easy to understand|common|very easy|elementary|plain|fundamental|simplified|convenient|trouble-free|standard|clear|clear-cut|straight-forward|essential|not difficult|easy-to-follow|simplistic|natural|fast|small|user-friendly|primary|not hard|everyday|clean|excellent|n easy|very|direct to the point|every day|undemanding|simply|trouble free|rather-simple|easy-to-understand} spinner
    Took 5 minutes in C# ;)
     
  4. mintuz

    mintuz Newbie

    Joined:
    Jan 15, 2011
    Messages:
    42
    Likes Received:
    3
    Home Page:
    cheers bud, very helpful. Trying to make something auto-spin :D