repl.it
@kironroy/

strings

C#

strings interpolation, format, builder

fork
loading
Files
  • main.cs
  • main.exe
  • notes.txt
  • StringUtility.cs
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
using System.Text;

class MainClass {
 public static void Main(string[] args) {


 

  string firstName = "Rohan";
  string middleName = "Rigel";
  string lastName = "Roy";

 // string format

  var fullNameFormat = string.Format("My name, using string format is: {0} {1} {2}", firstName, middleName, lastName);

  Console.WriteLine(fullNameFormat);

  
  Console.WriteLine("------------------------"); 

  Console.WriteLine(); // breakline

  var fullName = "Grace Kelly";

  Console.WriteLine("Trim: '{0}'", fullName.Trim());
  Console.WriteLine("ToUpper: '{0}'", fullName.Trim().ToUpper());

  Console.WriteLine(); // breakline

  // convert number to string 

  var strNumber = "42";
  var age = Convert.ToByte(strNumber);
  Console.WriteLine(age);

  Console.WriteLine(); // breakline

  // convert string to number 

  float price = 29.95f;
  Console.WriteLine(price.ToString("C"));

  Console.WriteLine(); // breakline

  // string builder 

  var builder = new StringBuilder("Hello World");

  builder
   .Append('-', 10)
   .AppendLine()
   .Append("Header")
   .AppendLine()
   .Append('-', 10)
   .Replace('-', '+')
   .Remove(0, 10)
   .Insert(0, new string('-', 10));

  Console.WriteLine(builder);

  Console.WriteLine("First Char: " + builder[0]);

  Console.WriteLine(); // breakline

  // string utility 

  var sentence = "This is going to be a really really really really really long text.";
  var summary = StringUtility.SummerizeText(sentence, 25);
  Console.WriteLine(summary);



 }
}