Solved

Enumerable.Select

Posted on 2010-09-21
2
407 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
Comment Utility

            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
Comment Utility
try this:

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Setting location of a form 4 21
visual Basic Net vs c# net 8 53
Why, and when, to use Windows Workflow 1 16
ConsoleSql 1 14
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now