Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

How to Extract Digits From a String in C#

How to Extract digits from a string in Csharp. String is a common data type which we use in our code but some time we have to perform some kind of function on string. It is a example of how you can extract numeric digits. Follow the following steps:
Requirement for the use of timer control is following.

- Operating System : Windows XP, Windows 7 , Vista
- Platform : .Net 2.0 or greater
- IDE : Visual Studio
- Language : Csharp

Now Follow the following steps :

- Create New Project on Visual Studio
- Select language C#
- Now Select the Console Application

Add this to your code at top :

-
using System.Text.RegularExpressions;

Use the Following Function :

public static string[] ExtractDigits(string data)
{
System.Text.RegularExpressions.MatchCollection matches
= System.Text.RegularExpressions.Regex.Matches(data,@"(\d+\.?\d*|\.\d+)");
string[] MatchList = new string[matches.Count];
int c = 0;
foreach (System.Text.RegularExpressions.Match match in matches)
{
MatchList[c] = match.ToString();
c++;
}
return MatchList;
}
Now you can use this function in many forms for example im using it for sum of digits :

static void Main(string[] args)
{
string st = "sfdsdfj3w4ew3434mnskjfns34wq34";
int sum = 0;
string[] arra = ExtractDigits(st);

for (int i = 0; i < arra.Length; i++) { Console.WriteLine(arra[i]); sum+= Convert.ToInt32(arra[i]); } Console.WriteLine("SUM is : "+sum.ToString()); Console.ReadLine(); }

How To Create A Log File

We start from the simple question that why we need to create a log file in our application. Simple is that log file keep record of all transaction of data or tells us about the action that we done in application. It help us to recover all previous data. I read many forum related to coding from where I get the question, is there any kind of built in function or .dll in C# that maintains log file. So answer to that question is that there is no such a function or .dll that handle this event. For this purpose I will suggest that y u not make your own program that help you to create a log file.

How To Create Hot Key in Windows Application With Csharp

This is my 4th Tutorial about the basic Windows Programming. Hot key are such key which we embed is in our application for ease of user. For example when we write a URL in browser we write Google and then press Ctrl+Enter then URL look like this http://www.google.com it’s a basic example. we use Alt+F4 to close any kind of window. If you never done this before then your may be thinking that it is very difficult but dear you will surprise to know that its so much easy to create a Hot Key in Windows Application with Csharp.

sabre-oled

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Powered by Blogger