Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
C# practice
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { Program prg = new Program(); /*Given a string with fixed value = “MYR 1045.54”, write a function that can remove the currency at the front and return 1045.54 in string format*/ string Currency_Remove = prg.Question_One("MYR 1045.54"); Console.WriteLine(Currency_Remove); /*Given a string with fixed value = “MYR 1045.54", write a function can return ” RM 1045.00" in string format*/ string Currency_Value_Replace = prg.Question_Two("MYR 1045.54"); Console.WriteLine(Currency_Value_Replace); /* Given a string with any value, for example, “MYR 1045.54”, write a function can return double value with “MYR 1045.00", with the function can receive any amount of string value with MYR currency is fixed. */ string Price_Return_Double = prg.Question_Three("1045.54"); Console.WriteLine("MYR {0}", Price_Return_Double); /* Given mobile phone number in string = “013 4471042”, write a function that will split the string into two string, first is the country code, second is the phone number. For example, this string will be split into string A = “013", string B = “4471042”*/ string phone_number = "013 4471042"; prg.Question_Four(phone_number); } public string Question_One(string Price) { string Currency_Remove; Currency_Remove = Price.Remove(0,4); return Currency_Remove; } public string Question_Two(string Price2) { string Currency_Value_Replace; Currency_Value_Replace = Price2.Replace("MYR", "RM").Replace(".54", ".00"); return Currency_Value_Replace; } public string Question_Three(string Price3) { string Price_Return_Double; Price_Return_Double = Convert.ToString(Double.Parse(Price3)).Replace("54","00"); return Price_Return_Double; } public string Question_Four(string phone_number) { int count = 1; Char[] separator = { ' ' }; String[] phonenumList = phone_number.Split(separator, StringSplitOptions.RemoveEmptyEntries); foreach(String p in phonenumList) { Console.WriteLine("String " + count + ":" + p); count++; } return null; } } }
run
|
edit
|
history
|
help
0
AKASH B AND HIS CODES\\
Project Euler No 2
Print 2D Array
Xamarin
Search Element In Array-Recursive
sortowania przez wstawienie Correct
Fórum ➡ Building a List<> with questions and answers, from data in TXT file, using LINQ ♦
Shift Example
5. Generics
smallestof3