Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Enumerable.Select

Posted on 2010-09-21
2
410 Views
Last Modified: 2013-11-11
How to print only the digits from the ID field?
(without using basic substring and indexOf functions to check each ID)

            DataTable dt = new DataTable();
            dt.Columns.Add("ID", typeof(String));
            dt.Rows.Add("USB22345");
            dt.Rows.Add("USC33399");
            dt.Rows.Add("USD66777");

            var query = from c in dt.AsEnumerable()
            select c["ID"];

            foreach (string item in query)
                Console.WriteLine(item.Select(c => char.IsDigit(c)));

Open in new window

0
Comment
Question by:mawingpui
2 Comments
 
LVL 16

Assisted Solution

by:kris_per
kris_per earned 125 total points
ID: 33726094

            foreach (string item in query)
            {
                char[] numsArray = item.ToCharArray().Where(c => char.IsDigit(c)).ToArray();
                string numString = new StringBuilder().Append(numsArray).ToString();
                Console.WriteLine(numString);
            }

Open in new window

0
 
LVL 12

Accepted Solution

by:
kumar754 earned 125 total points
ID: 33726907
try this:

foreach (string item in query)
                Console.WriteLine(string.Join( null,System.Text.RegularExpressions.Regex.Split( item, "[^\\d]" ) ));
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question