• IsNormalized() Satrni C formasi bo’yicha Unicode kodlarida chiqaradi LastIndexOf()
  • Length Satr uzunligini chiqaradi Remove()
  • StartsWith() Satr ko’rsatilgan belgi bo’yicha boshlansa True aks holda False Substring()
  • ToCharArray() Satrni char turiga o’tkazish Misollar
  • Kompyuter tizimlari kafedrasi




    Download 5,29 Mb.
    bet140/154
    Sana08.01.2024
    Hajmi5,29 Mb.
    #131939
    1   ...   136   137   138   139   140   141   142   143   ...   154
    Bog'liq
    Majmua

    ToUpper()

    Satarni katta harflar ko’rinishida ko’rsatadi

    Insert()

    Satrga bironta belgi yoki satrni joylashtiradi

    IsNormalized()

    Satrni C formasi bo’yicha Unicode kodlarida chiqaradi

    LastIndexOf()

    Satrdagi oxirgi belgini chiqaradi

    Length

    Satr uzunligini chiqaradi

    Remove()

    Satrdagi belgilarni o’chiradi

    Replace()

    Satrga belgini joylashtiradi

    Split()

    Satrni biron belgi bo’yicha chiqaradi

    StartsWith()

    Satr ko’rsatilgan belgi bo’yicha boshlansa True aks holda False

    Substring()

    Satrdan biron qism kesib olish.

    ToCharArray()

    Satrni char turiga o’tkazish



    Misollar
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApp4


    {
    class Program
    {
    static void Main(string[] args)
    {
    string firstname;
    string lastname;
    firstname = "Steven Clark";
    lastname = "Clark";
    Console.WriteLine(firstname.Clone());
    Console.WriteLine(firstname.CompareTo(lastname));
    Console.WriteLine(firstname.Contains("ven"));
    Console.WriteLine(firstname.EndsWith("n"));
    Console.WriteLine(firstname.Equals(lastname));
    Console.WriteLine(firstname.GetHashCode());
    Console.WriteLine(firstname.GetType());
    Console.WriteLine(firstname.GetTypeCode());
    Console.WriteLine(firstname.IndexOf("e"));
    Console.WriteLine(firstname.ToLower());
    Console.WriteLine(firstname.ToUpper());
    Console.WriteLine(firstname.Insert(0, "Hello"));
    Console.WriteLine(firstname.IsNormalized());
    Console.WriteLine(firstname.LastIndexOf("e"));
    Console.WriteLine(firstname.Length);
    Console.WriteLine(firstname.Remove(5));
    Console.WriteLine(firstname.Replace('e', 'i'));
    string[] split = firstname.Split(new char[] { 'e' });
    Console.WriteLine(split[0]);
    Console.WriteLine(split[1]);
    Console.WriteLine(split[2]);
    Console.WriteLine(firstname.StartsWith("S"));
    Console.WriteLine(firstname.Substring(2, 5));
    Console.WriteLine(firstname.ToCharArray());
    Console.WriteLine(firstname.Trim());
    }
    }
    }
    1. Satrni o’qish
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace Getline


    {
    class Program
    {
    static void Main(string[] args)
    {
    int n;
    n = Convert.ToInt32(Console.ReadLine());
    var input = new char[n];
    for (var i = 0; i < input.Length; i++)
    {
    input[i] = Console.ReadKey().KeyChar;
    }
    Console.WriteLine();
    Console.WriteLine(input);
    Console.ReadKey();
    }
    }
    }

    2. Satr uzunligin aniqlash


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

    namespace Getline


    {
    class Program
    {
    static void Main(string[] args)
    {
    int n;
    n = Convert.ToInt32(Console.ReadLine());
    var input = new char[n];
    for (var i = 0; i < input.Length; i++)
    {
    input[i] = Console.ReadKey().KeyChar;
    }
    Console.WriteLine();
    Console.WriteLine(input.Length);
    Console.ReadKey();
    }
    }
    3. Satrdagi turli harflar miqdori
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace Getline


    {
    class Program
    {
    static void Main(string[] args)
    {
    int n, k;
    double s = 0;
    n = Convert.ToInt32(Console.ReadLine());
    var input = new char[n];
    for (var i = 0; i < input.Length; i++)
    {
    input[i] = Console.ReadKey().KeyChar;
    }
    for (var i = 0; i < input.Length; i++)
    {
    if (input[i] != ' ')
    {
    k = 0;
    for (var j = 0; j < input.Length; j++)
    {
    if (input[i] == input[j] || Math.Abs(input[i] - input[j]) == 32)
    {
    k++;
    s = s + 1.0 / (k);
    }
    }
    }
    }
    Console.WriteLine("\nSatrdagi turli harflar miqdori:" + ((int)s-1));
    Console.ReadKey();
    }
    }
    }

    4. Satrlarni nusxalash


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

    namespace Getline


    {
    class Program
    {
    static void Main(string[] args)
    {
    int n;
    n = Convert.ToInt32(Console.ReadLine());
    var input = new char[n];
    var input1 = new char[n];
    for (var i = 0; i < input.Length; i++)
    {
    input[i] = Console.ReadKey().KeyChar;
    Array.Copy(input, input1, 2);
    }
    Console.ReadLine();
    Console.WriteLine(input1);
    Console.ReadKey();
    }
    }
    }

    5. Satrlarni solishritish


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

    namespace Getline


    {
    class Program
    {
    static void Main(string[] args)
    {
    int n;
    n = Convert.ToInt32(Console.ReadLine());
    var input = new char[n];
    var input1 = new char[n];
    for (var i = 0; i < input.Length; i++)
    {
    input[i] = Console.ReadKey().KeyChar;
    input1[i] = Console.ReadKey().KeyChar;
    Console.WriteLine(input[i].CompareTo(input1[i]));
    }
    Console.ReadKey();
    }
    }
    }

    6. Satrdagi harflar registrlarini almashtirsh


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

    namespace Getline


    {
    class Program
    {
    static void Main(string[] args)
    {
    char[] new_str = new char[50];
    string str;
    int ch;
    Console.Write("Enter String : ");
    str = Console.ReadLine();
    for (int i = 0; i < str.Length; i++)
    {
    ch = (int)str[i];
    if (ch > 64 && ch < 91)
    {
    ch = ch + 32;
    new_str[i] = Convert.ToChar(ch);
    }
    else
    {
    ch = ch - 32;
    new_str[i] = Convert.ToChar(ch);
    }
    }
    Console.Write(new_str);

    Console.ReadKey();


    }
    }
    }

    7. Teskari tartiblash


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

    namespace Getline


    {
    class Program
    {
    static void Main(string[] args)
    {
    int n;
    n = Convert.ToInt32(Console.ReadLine());
    var input = new char[n];
    for (var i = 0; i < input.Length; i++)
    {
    input[i] = Console.ReadKey().KeyChar;
    Array.Reverse(input);
    Console.WriteLine(input);
    }
    Console.ReadKey();
    }
    }
    }

    8. Belgini izlash


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

    namespace Getline


    {
    class Program
    {
    static void Main(string[] args)
    {
    int n;
    var index = -1;
    n = Convert.ToInt32(Console.ReadLine());
    var input = new char[n];
    for (var i = 0; i < input.Length; i++)
    {
    input[i] = Console.ReadKey().KeyChar;
    if (input[i] == 'E')
    index = i;
    //var index = Array.FindIndex(input, c => c.Equals('E'));
    //Console.WriteLine(index);
    }
    Console.ReadKey();
    }
    }
    }
    String turidan char turiga o’tish
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.IO.Compression;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace EKUB


    {
    class Program
    {
    static void Main(string[] args)
    {
    string str = "Csharpda massivni konvertatsiya qilish";
    char[] c = str.ToCharArray();
    Console.WriteLine(c);
    Console.ReadLine();
    }
    }
    }


    Download 5,29 Mb.
    1   ...   136   137   138   139   140   141   142   143   ...   154




    Download 5,29 Mb.