String methods

Substring() -> returns substring into substring

Console.WriteLine(longstring.Substring(5));
Console.WriteLine(longstring.Substring(5,10));
Console.WriteLine(longstring.Substring(5,10,100));//Error

Error : xatto bo’ladi,sababi – hajmidan o…


This content originally appeared on DEV Community and was authored by Sabrina

Substring() -> returns substring into substring

Console.WriteLine(longstring.Substring(5));
Console.WriteLine(longstring.Substring(5,10));
Console.WriteLine(longstring.Substring(5,10,100));//Error

Error : xatto bo'ladi,sababi - hajmidan oshib ketdi.

Replace() -> replace the specified old character with specified

var longString = "This guy is strongman";
Console.WriteLine(longstring.Replace("is","IS"));
Console.WriteLine(longstring.Replace("very","VERY"));
Console.WriteLine(longstring.Replace("iS","IS", StringComparison.CurrentCultureIgnoreCase));

Join() -> joins the given string using the specified separator;

string [] words = {"apple","banana","cherry"};
string result = string.Join("-",words);
Console.WriteLine(result);

string [] words2 = {"book","pen","notebook"};
string result2 = string.Join("|",words2);
Console.WriteLine(result2);

Remove() -> returns characters from a string
Berilgan tekstdan ochiradi

string tekst = "Hello world";
string tekst1 = tekst.Remove(1,5);
Console.WriteLine(tekst1);

PadLeft() -> returns a string padded with spaces or with specified Unicode character
PadLeft() -> tekstni chap tomonidan nechtadur joy ajratib beradi

string tekst = "Hello world";
string tekst1 = tekst.PadLeft(10,'0');
string tekst2 = tekst.PadLeft(10);
Console.WriteLine(tekst1);
Console.WriteLine(tekst2);

PadRight() -> returns a string padded with spaces or with specified Unicode character
PadRight() -> tekstni ong tomonidan nechtadur joy ajratib beradi

string tekst3 = "Hello world";
string tekst4 = tekst.PadLeft(10,'0');
string tekst5 = tekst.PadLeft(10);
Console.WriteLine(tekst4);
Console.WriteLine(tekst5);

ToCharArray -> converts to string to a char array

string tekst = "Hello";
char [] charArray = tekst.ToCharArray();
foreach(char c in charArray)
{
    Console.WriteLine(c);
}

LastIndexOf() - returns index of the last occurance of specified string

string tekst2 = "Hello world";
int index = tekst2.LastIndexOf("o");
int index2 = tekst2.IndexOf("o");
Console.WriteLine(index);
Console.WriteLine(index2);


This content originally appeared on DEV Community and was authored by Sabrina


Print Share Comment Cite Upload Translate Updates
APA

Sabrina | Sciencx (2024-08-23T17:39:42+00:00) String methods. Retrieved from https://www.scien.cx/2024/08/23/string-methods-2/

MLA
" » String methods." Sabrina | Sciencx - Friday August 23, 2024, https://www.scien.cx/2024/08/23/string-methods-2/
HARVARD
Sabrina | Sciencx Friday August 23, 2024 » String methods., viewed ,<https://www.scien.cx/2024/08/23/string-methods-2/>
VANCOUVER
Sabrina | Sciencx - » String methods. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/23/string-methods-2/
CHICAGO
" » String methods." Sabrina | Sciencx - Accessed . https://www.scien.cx/2024/08/23/string-methods-2/
IEEE
" » String methods." Sabrina | Sciencx [Online]. Available: https://www.scien.cx/2024/08/23/string-methods-2/. [Accessed: ]
rf:citation
» String methods | Sabrina | Sciencx | https://www.scien.cx/2024/08/23/string-methods-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.