0

Okay, so let's say I have a textbox that you can enter something like

Sebastian Soria 3'|12' Digano
Nam Tae-Hee 23', 45'|33' Julio Vezbek

And that textarea does this upon focusing your mouse out of it, the texarea gets read line by line and each line looks for its delimeter "|" and then splits it up and divides that in home and away scorer.

Here's a JS fiddle: http://jsfiddle.net/cu24k/

I could easily do it so if it's above 10, to scrap the last 4 characters of " XX'" and 3 do " X'" and split that up and color/bold it. But then I realized, what if they scored more than once? It would be 23', 45' or longer!

So, I thought... what if I can just take apart any apostrophe, comma and number and color/bold that.

Is there a way?

2
  • 5
    scrap the last 4 characters of " XX'" and 3 do " X'" and split that up and color/bold it Could you try to rephrase this? Or show it being done in your fiddle? I can't be the only one who doesn't understand what you're trying to say there. Commented Mar 21, 2014 at 18:32
  • Since home array would be something like Testing '4 then I could take the '4 by taking the last -3 using substr of the string or -4 if it was it was more than 9 minutes. Commented Mar 21, 2014 at 19:22

1 Answer 1

1

I'm not 100% sure what you were trying to do, but I threw together what I think you were going for: http://jsfiddle.net/cu24k/1/

Here is the updated JS:

 $(document).ready(function () {
     $('.scorers').on('change', function () {

         $("#home_scorers").text("");
         $("#away_scorers").text("");

         var lines = $('.scorers').val().split('\n');
         for (var i = 0; i < lines.length; i++) {
             var split      = lines[i].split('|');
             // get home data
             var home       = split[0];
             var homeIndex  = home.search( /\d+\'/ );
             var homeTeam   = home.substr( 0, homeIndex );
             var homeScore  = home.substr( homeIndex );
             // get away data
             var away       = split[1];
             var awayIndex  = away.lastIndexOf( "'" ) + 1;
             var awayScore   = away.substr( 0, awayIndex );
             var awayTeam  = away.substr( awayIndex );
             // output data
             $("#home_scorers").append(
                 "<div>" + homeTeam +
                 "<b>" + homeScore + "</b>" +
                 "</div>");
             $("#away_scorers").append(
                 "<div>" +
                 "<b>" + awayScore + "</b>" +
                  awayTeam + "</div>");
         }

     });

 });
Sign up to request clarification or add additional context in comments.

2 Comments

That's exactly what I was looking for. Thank you! Do you mind explaining this? From what I see you plit it up and searched individually for ', 0-9 and commas and... from there you took those apart.. and did things.. Hmm
Sure. Since the order is different, I had to separately handle home and away. For home, I searched for the first instance of ##', allowing 1+ digits followed by '. For the away team, I searched for the last index of a ' to find where it switched from scores to team name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.