How do I use Regex to extract characters from string?

0 favourites
  • 2 posts
From the Asset Store
120 Epic Fire FX Animations + 2 Bonus Characters. Contains 3000+ frames and a lot of Pixel Art Sprites
  • Hello all,

    I'm developing 4 video games to help build cyber security awareness among high-school kids. For one game I'm taking them thru a series of steps which help them in creating a strong password. One of the steps requires them to enter the acronym of the phrase they entered initially and I need a way for the game to validate if they entered the correct acronym before allowing them to move forward.

    Basically I'm trying to write a function to "acronymize" text entered into a textbox by the user via the keyboard.

    For example, if the user enters the phrase "hey what's cooking good looking", initially, this text is saved to text variable say "UserPhrase", then the user is prompted to enter the acronym of this phrase, the game/function should compute the acronym of this stored phrase and compare it to the acronym entered by the user, if it is correct, a corresponding text object should display the result which in this case would be "hwcgl" and allow the user to move forward in the game.

    I know how to carry this out in C++ but I am having a high degree of difficulty translating it to Construct 2.

    #include <iostream>

    #include <string>

    #include <cctype>

    using namespace std;

    string acronym(string str);

    int main()

    {

    string str;

    while (true)

    {

    cout << "\nPlease enter a string: ";

    getline(cin, str);

    if (str == "")

    {

    break;

    }

    cout << "\n\nThe acronym is \"" << acronym(str) << "\"" << "\n";

    }

    system("PAUSE");

    return 0;

    }

    string acronym(string str)

    {

    string phrase = "";

    phrase = str[0];

    for (int i = 0; i < str.length(); i++)

    {

    if (str == ' ')

    {

    phrase += str[i+1];

    }

    }

    return phrase;

    }

    Can anyone show me how to achieve this using Regex?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I don't think a regex is the solution. You should probably do something like this :

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)