Is there any function in C#, if we give the numeric value of a month it will give character as an output.
For example:
Input is say 1
Output is January
Input is say 12
Output is December
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jan 8, 2012, 11:36 AM
VulpesPosted Jan 9, 2012, 2:44 PM
http://msdn.microsoft.com/en-us/library/system.string.substring.aspx
Posted Jan 9, 2012, 2:41 PM
Thank you for your help.
int m = int.Parse(bDay.Substring(0, 2)); This code is new to me. Please give me relevant website addresses where I can learn about this code.
VulpesPosted Jan 9, 2012, 12:46 PM
You therefore need to enter a birth date in the format 01/01/1111 etc. or change it so that it can cope with single digit months or days.
Posted Jan 9, 2012, 12:33 PM
Name #1 A
Phone No 123456
Birth Day (mm/dd/yyyy) 1/1/1111
Name #2 Q
Phone No 654321
Birth Day (mm/dd/yyyy) 2/2/2222
Name #3 Z
Phone No 123567
Birth Day (mm/dd/yyyy) 3/3/3333
Name #1 A Phone No 123456 Birth Day 1/1/1111
Name #2 Q Phone No 654321 Birth Day 2/2/2222
Name #3 Z Phone No 123567 Birth Day 3/3/3333
Enter friend's name A
At this point there is an error signal saying that Formal Exemptions was unhandled. It is indicating following step.
int m = int.Parse(bDay.Substring(0, 2));
Program is attached.
VulpesPosted Jan 9, 2012, 11:45 AM
Posted Jan 8, 2012, 9:15 PM
using System;
using System.Globalization;
namespace _6e13_a_b_c_d_
{
class Program
{
static void Main(string[] args)
{
Friend[] friend = new Friend[3];
for (int x = 0; x < friend.Length; ++x)
{
friend[x] = new Friend();
Console.Write("Name #{0} ", x+1);
friend[x].setName(Console.ReadLine());
Console.Write("Phone No ");
friend[x].setPNo(Convert.ToInt32(Console.ReadLine()));
Console.Write("Birth Day (mm/dd/yyyy) ");
friend[x].setBday(Console.ReadLine());
Console.WriteLine();
}
Array.Sort(friend);
for (int x = 0; x < friend.Length; ++x)
Console.WriteLine("Name #{0} {1} Phone No {2} Birth Day {3}", x + 1, friend[x].getName(), friend[x].getPNo(), friend[x].getBday());
Console.WriteLine();
Console.Write("Enter friends name ");
string fn = Console.ReadLine();
for (int x = 0; x < friend.Length; ++x)
if (friend[x].getName()==fn)
Console.WriteLine("Phone No {0} Birth Day mm/dd/yyyy {1}", friend[x].getPNo(), friend[x].getBday());
Console.WriteLine();
Console.Write("Birthday month in a numeric format: ");
int m = Convert.ToInt32(Console.ReadLine());
string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(m);
Console.WriteLine("Birthday is in {0}", monthName);
Console.ReadKey();
}
}
}
internal class Friend : IComparable
{
private string name;
private int pNo;
private string bDay;
public string getName()
{
return this.name;
}
public void setName(string name)
{
this.name = name;
}
public int getPNo()
{
return this.pNo;
}
public void setPNo(int pNo)
{
this.pNo = pNo;
}
public string getBday()
{
return this.bDay;
}
public void setBday(string bDay)
{
this.bDay = bDay;
}
public int CompareTo(Friend firstName)
{
return string.Compare(this.name, firstName.name);
}
}
VulpesPosted Jan 8, 2012, 12:12 PM
using System;
using System.Globalization;
class Test
{
static void Main()
{
Console.Write("Month No ");
int m = Convert.ToInt32(Console.ReadLine());
string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(m);
Console.WriteLine(monthName);
Console.ReadKey();
}
}
Notice also that it's easy to get the month names in different languages with this approach. For example, if you change the above line to:
string monthName = CultureInfo.GetCultureInfo("fr-FR").DateTimeFormat.GetMonthName(monthNumber);
and enter 11 for monthNumber, then the output will be:
novembre
Posted Jan 8, 2012, 12:02 PM
string monthName = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(m);
Please tell me the correct using directive for this.
Also thank you for your help.
using System;
class Test
{
static void Main()
{
Console.Write("Month No ");
int m = Convert.ToInt32(Console.ReadLine());
string monthName = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(m);
Console.WriteLine(monthName);
Console.ReadKey();
}
}
VulpesPosted Jan 8, 2012, 11:00 AM
Try it and see.
Prabhu RajaPosted Jan 8, 2012, 11:00 AM
I think there is no Build in function in .Net to do this. You may try this function
1) Give " Microsoft.SqlServer.Smo " dll reference to your Project.
2) Try
using Microsoft.SqlServer.Management.Smo;
If this post helps you, then mark as "Correct Answer". Thank You
Posted Jan 8, 2012, 10:56 AM
For example:
Console input is 1
Console output is January
VulpesPosted Jan 8, 2012, 10:36 AM