Answers for "split a string and store in numbers"

1

java separate the numbers from string

// string contains numbers
        String str = "The price of the book is $49";
        // extract digits only from strings
        String numberOnly = str.replaceAll("[^0-9]", "");
        // print the digitts
        System.out.println(numberOnly);
Posted by: Guest on October-25-2021
0

numbers split

const num = 1234567;
const strNum = String(num);

function getPartialString(str, len) {
  const result = [];
  for (let i = 0; i < strNum.length - (len - 1); ++i) {
    result.push(strNum.slice(i, i + len));
  }
  return result;
}
console.log(getPartialString(strNum, 3));
console.log(getPartialString(strNum, 4));
console.log(getPartialString(strNum, 5));
Posted by: Guest on January-17-2022

Code answers related to "split a string and store in numbers"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language