show some operations on strings without using inbuilt methods of microsoft in C#


Category: C# Tags: C#, Interview Question

1. replace vowels with special character _ (underscore) 2. convert all letters of a string in upper case


Like 1 Person
Asked on 20 March 2014
Nikhil Joshi

Nikhil Joshi
Ceo & Founder at Dotnetlovers
Atricles: 127
Questions: 9
Given Best Solutions: 8 *

Answers:

Nikhil Joshi
© nikhil joshi :P Ans 1.
protected void Page_Load(object sender, EventArgs e)
    {
        string s = "abcdefghijklmnopqrstuvwxyz";
        char[] vowels = new char[] { 'a', 'e', 'i', 'o', 'u' };
        char[] newstring =new char[s.Length];
        bool k=false;
        for (int i = 0; i < s.Length; i++)
        {
            for (int j = 0; j < vowels.Length; j++)
            {
                if (s[i] == vowels[j])
                {
                    k = true; break;
                }
            }
            if (k)
            {
                newstring[i] = '_'; k = false;
            }
            else
            { newstring[i] = s[i]; }
        }
        foreach (object o in newstring)
        {
            Response.Write(o);
        }
    }
Ans 2.
protected void Page_Load(object sender, EventArgs e)
    {
        string s = "akjddiDJGJfjsaEr";
        char[] newstrng = new char[s.Length];
        for (int i = 0; i < s.Length; i++)
        {
            int j = s[i];
            if (j >= 97 && j <= 122)
            {
                j = j - 32;
                newstrng[i] = (char)j;
            }
            else
            {
                newstrng[i] = s[i];
            }
        }
        foreach (object o in newstrng)
        {
            Response.Write(o);
        }
    }
Like 1 Person on 20 March 2014

You are not loggedin, please login or signup to add comments:

Existing User

Login via:

New User



x