This site requires JavaScript, please enable it in your browser!
Greenfoot back
JasonZhu
JasonZhu wrote ...

2014/4/28

Recognizing underscores from integers from input

1
2
JasonZhu JasonZhu

2014/4/28

#
I will give that a try asap. I'm a bit busy at the moment, ill provide an update asap. Thank you once again.
JasonZhu JasonZhu

2014/4/28

#
I tried the modifications to my new code and I'm still getting no output.
JasonZhu JasonZhu

2014/4/28

#
I'm now leaning towards substring. Too bad I'm away from the computer meantime.
danpost danpost

2014/4/28

#
I came up with this method:
// called with something like
String road = roadStep("___3_31__2__");
// and using this method
private String roadStep(String input)
{
    String output = "";
    String under = "";
    for (int i=input.length()-1; i>=0; i--)
    {
        char c = input.charAt(i);
        if (c == '_')
        {
            under += "_";
            continue;
        }
        if (under.length() >= c-48)
        {
            output = c+under.substring(c-48)+output;
            under = under.substring(0, c-48);
        }
        else
        {
            if (c-48+i >= input.length())
                under += "_";
            else
                output = c+output;
        }
    }
    return under+output;
}
JasonZhu JasonZhu

2014/4/28

#
Thank you for your time and effort danpost, I'll let you know of its functionality as soon as im back home.
danpost danpost

2014/4/28

#
You should not have any problems with it. It was tested and tried before the posting.
JasonZhu JasonZhu

2014/4/29

#
Ok, thank you for your confirmation!
You need to login to post a reply.
1
2