Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,912 questions

51,844 answers

573 users

How to strip all non-numeric characters from string in C#

2 Answers

0 votes
using System;
using System.Linq;

class Program
{
    private static string removeNonNumeric(string s) {
        return new string(s.Where(c => char.IsDigit(c)).ToArray());
    }
    static void Main() {
        string s = "2a1-0/R@a9f#4K$$cC3K^htPam8vlQWhJ";

        s = removeNonNumeric(s);
        
        Console.Write(s);
    }
}



/*
run:

2109438

*/

 



answered Jun 15, 2020 by avibootz
0 votes
using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main() {
        string s = "2a1-0/R@a9f#4K$$cC3K^htPam8vlQWhJ";

        s = Regex.Replace(s, "[^.0-9]", "");
        
        Console.Write(s);
    }
}



/*
run:

2109438

*/

 



answered Jun 15, 2020 by avibootz

Related questions

2 answers 124 views
1 answer 120 views
2 answers 189 views
2 answers 196 views
...