Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Enumerable.Select

Posted on 2010-09-21
2
Medium Priority
?
426 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
[X]
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
2 Comments
 
LVL 16

Assisted Solution

by:kris_per
kris_per earned 500 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 500 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

Google Certified Professional - Cloud Architect

This course (1 of 3) is designed to help students who are interested in Google Cloud Platform (GCP) to become familiar with the platform, navigate the console and learn its capabilities. It will also prepare students for the Google Cloud Architect certification exam.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

704 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