Bird
0
0

How can you extract all numbers from the string "Order123Price456" using C# string methods?

hard🚀 Application Q9 of 15
C Sharp (C#) - Strings and StringBuilder
How can you extract all numbers from the string "Order123Price456" using C# string methods?
AUse a loop with Char.IsDigit and build a new string
BUse Substring with fixed indexes
CUse IndexOf to find numbers directly
DUse Contains to check for digits
Step-by-Step Solution
Solution:
  1. Step 1: Understand string methods limitations

    Substring and IndexOf cannot extract all digits scattered in string easily.
  2. Step 2: Use loop and Char.IsDigit to filter digits

    Loop through each char, check if digit, and append to new string to extract all numbers.
  3. Final Answer:

    Use a loop with Char.IsDigit and build a new string -> Option A
  4. Quick Check:

    Char.IsDigit + loop extracts digits [OK]
Quick Trick: Loop chars and check Char.IsDigit to extract numbers [OK]
Common Mistakes:
MISTAKES
  • Trying to use Substring for scattered digits
  • Using Contains which only checks presence
  • Expecting IndexOf to find multiple digits

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes