DotNet Mirror
  DNM facebook   DNM Google+   DNM Twitter   

Write C#.NET program to find the length of string without using library function

By Ashok Nalam on 13 Dec 2013 | Category: C# | Tagged: string .NET 
In one of forum, someone asked to Write C#.NET program to find the length of string without using library function. So in this snippet we will see find the length of string without using any built function or string function.
  Discuss Add Comment   |  
Add rating Rate this resource   

Introduction

In one of forum, someone asked to Write C#.NET program to find the length of string without using library function. So in this snippet we will see to find the length of string without using any built-in library function or string function.

using System;
namespace DotNetMirror
{
    class StringLengthWithOutLibraryFunction
    {
        static void Main()
        {
            string normalStr = "DotNetMirror";
            int charCount = 0;
            foreach (char chr in normalStr)
            {
                charCount = charCount + 1;
            }
            Console.WriteLine("string '{0}' length is: {1}",normalStr,charCount);
            Console.ReadKey();
        }
    }
}

Output:

string 'DotNetMirror' length is: 12
  Discuss Add Comment    
Add rating Rate this resource   
About the Contributor
Member Since : 10 Dec 2012
Member Points (Level) : 8926  (Professional)
Location : INDIA
Home Page : http://dotnetmirror.com
About : I am admin of this site.
Rate this resource
 
Add your Comment
Name Email WebSite
Captcha Refresh


Comments (0)
No comments found, click here to add comment.