Deleting first character in a string- getting rid the the front $ value sign

edited March 2017 in How To...

Hello All,

I know in python its as simple as the syntax String[1:] etc.

But I can not seem to find as simple as a way in java. I am wanting to loop through a series of dollar values and just get rid the the dollar sign to start using the values as ints to manipulate.

Thanks, Sam

Tagged:

Answers

  • Beautiful- exactly what I was after. That would be a similar idea for getting rid of any instances of a comma for example between numbers?

    Sam

  • edited March 2017

    @samuelnsweeney -- There are many ways to filter specific characters from a string, but if you are only going to remove a single character and of the strings are reasonably small then you could just split() and join() using the Processing built-ins:

    // remove commas from strings
    String num;
    String[] tmp;
    num = "100,000,000";
    println(num);
    tmp = split(num, ',');  // processing.org/reference/split_.html
    num = join(tmp, "");    // processing.org/reference/join_.html
    println(num);
    

    Concisely:

    String num = "100,000,000";
    num = join(split(num, ','),"");
    println(num);    // prints: 100000000
    
  • That sounds like a good way, thankyou Jeremy. The string document above shows what look like more complex ways like replace. etc

    Sam

Sign In or Register to comment.