-1

I would like to remove all text from a string and just leave any numbers that are in the string.

I found this answer to a very similar question

Removing text around a number using VBA

This works exactly as I would like it to except it returns only the first two numbers in the string. My data varies and may have up to eight numbers

"2 abc def 1 xyz 1 big 2 small 7 High 2 end finish 2 start"

should return 2 1 1 2 7 2 2

Thanks for any help

Community
  • 1
  • 1
JeffM
  • 1
  • 1
  • Thank you Jeeped I hadn't come across that other post. With what you directed me to there I have got very close to fixing my problem – JeffM Feb 17 '18 at 21:58

1 Answers1

0

Do you need VBA? Not clear from your question. Anyway, a solution (logic) to solve this applies to any language and is as follows:

You can take the string and go char by char with a for loop going to str.length - 1 (or just str.length if you do < instead of <=)

Having a single char, you can identify if it's a digit. If char is a digit, store it in a temp string and just keep adding chars to that string until the loop completes. Otherwise, do nothing and go to next index.

  • Yes I would like VBA – JeffM Feb 17 '18 at 06:34
  • Yes I would like VBA please. The answer here https://stackoverflow.com/questions/21085858/removing-text-around-a-number-using-vba does what I need except I need to return more than two numbers – JeffM Feb 17 '18 at 06:43