Click here to Skip to main content
12,445,916 members (61,306 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
Dear All,

In interview i was given a logical task

To print number from 1 to 50 asp.net C#

But it should be in this format

1
TWO
3
4
Five
6
.
.
.
.
.
.
11
1Two
13
14
1Five
till 50


means 2 must be replace with "TWO" and 5 with Five

how to do this

and ha

it must be further modified to accept input from user like lowest number and highest number and same replacement must be done in this series also how to solve this

please help me
Thanks in advance
Posted 2-Feb-13 20:49pm
Comments
Sandeep Mewara 3-Feb-13 3:09am
   
It does not work like this here.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.
Santhosh Babu Mahimairaj 25-Sep-14 6:42am
   
dude wt abt 22 25 ?
we need to display TWO TWO or 2TWO
like that 25 also TWO FIVE or 2FIVE
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You can use Sring.Replace:
string str = "12345";
str = str.Replace("2", "Two").Replace("5", "Five");
// str is now "1Two34Five";

Cheers,
Edo
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int count;
Console.WriteLine("enter range");
count = Convert.ToInt32(Console.ReadLine());

for (int i = 0; i < count; i++)
{
string str = Convert.ToString(i);
string str1 = str.Replace("2", "Two").Replace("5", "Five");

Console.WriteLine(str1);
}
Console.ReadLine();
}
}
}
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160811.3 | Last Updated 24 Sep 2014
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100