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

AutoSpin c#

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

  1. mintuz

    mintuz Newbie

    Joined:
    Jan 15, 2011
    Messages:
    42
    Likes Received:
    3
    Home Page:
    Right guys here is my problem, I am trying to make a autospinner using a database of words to match agasint words in a string.How can i add brackets around each word within a string along with the | and the opposite word..

    for example if I have a var called theString with the string "Hello world my name is mintuz" How could I add { } around each word along with the or bracket and a possible word read from the database. so it reads...

    "{Hello | Hi} {world | Univerise} {my} {name | ID} {is | may be } {mintuz}"
     
  2. Krippleintime

    Krippleintime Registered Member

    Joined:
    May 12, 2010
    Messages:
    96
    Likes Received:
    13
    Location:
    Graphic Location Unknown
    Code some regex to find each word then replace it with using the | and {}
     
  3. cashfap

    cashfap Junior Member

    Joined:
    May 5, 2010
    Messages:
    115
    Likes Received:
    14
    Location:
    Estonia
    You need to add the brackets on the code side. I don't believe you can add those brackets in SQL and if you can it's most likely more trouble than it's worth.
     
  4. squark

    squark Junior Member

    Joined:
    May 22, 2008
    Messages:
    156
    Likes Received:
    1,206
    if I understand what you're looking for then something along these lines should work...

    Code:
    string target = "Hello world my name is mintuz";
    string[] words = target.Split(' ');
    StringBuilder result = new StringBuilder();
    
    foreach (var word in words)
    {
        // Perform your replacement word search
        string word2 = ...;
        result.AddFormat("{{{0} | {1}}} ", word, word2);
    }
    return result.ToString();
    
    That should give you something close to what you're looking for. I typed this straight into the reply box, so there may be a typo there... but the logic works. And you won't need any regex to make it work.

    Hope this helps.