Sunday, 5 April 2015

praktikum program pengenalan string

Hai sobat jufrikablog kali ini saya sedikit menjelaskan tentang contoh contoh penggunaan method dari string yang sangat beragam ada lower, upper , insert , remove, join , split dll , nah bagaimana cara membuatnya? cek sob


  1. Buat Desain seperti gambar diatas sob
  2. Gunakan fungsi fungsi yang bisa sobat download di modul praktikum ini
  3. nah buat kodingannya seperti source di bawah ini
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms; namespace latihan
    {
    public partial class MainForm : Form
    {
    //data 1
    private string strText = “My String”;
    //data 2
    private string str = “My String is a long string”;
    public MainForm()
    {
    InitializeComponent();
    textBox1.Text = strText;
    textBox10.Text = str;
    }
    //data 1
    void insert(){
    int a = Convert.ToInt16(textBox2.Text);
    string b = Convert.ToString(textBox3.Text);
    string test = strText.Insert(a, b) ;
    textBox19.Text = test; }
    void rem(){
    int a = Convert.ToInt16(textBox4.Text);
    int b = Convert.ToInt16(textBox5.Text);
    string test = strText.Remove(a, b);
    textBox20.Text = test;}
    void lower(){
    string test = strText.ToLower();
    textBox17.Text = test;}
    void upper(){
    string test = strText.ToUpper();
    textBox18.Text = test;}
    void join(){
    string a = Convert.ToString(textBox6.Text);
    string b = Convert.ToString(textBox7.Text);
    string c = Convert.ToString(textBox8.Text);
    string[] d = { a, b };
    string test = String.Join(c, d);
    textBox21.Text = test;}
    void split(){
    string a = Convert.ToString(textBox9.Text);
    string[] b = strText.Split();
    textBox23.Text = string.Join(a, b);}
    void trim(){
    string test = strText.Trim();
    textBox22.Text = test;}
    //data 2
    void io(){
    string a = Convert.ToString(textBox11.Text);
    int test = str.IndexOf(a);
    string b = Convert.ToString(test);
    textBox24.Text = b;}
    void io2(){
    string a = Convert.ToString(textBox12.Text);
    int b = Convert.ToInt16(textBox13.Text);
    int test = str.IndexOf(a, b);
    string c = Convert.ToString(test);
    textBox25.Text = c;}
    void lio(){
    string a = Convert.ToString(textBox14.Text);
    int test = str.LastIndexOf(a);
    string b = Convert.ToString(test);
    textBox26.Text = b;}
    void lio2(){
    string a = Convert.ToString(textBox15.Text);
    int b = Convert.ToInt16(textBox16.Text);
    int test = str.LastIndexOf(a, b);
    string c = Convert.ToString(test);
    textBox27.Text = c;}
    //button data 1
    void Button3Click(object sender, EventArgs e)
    {
    insert();
    }
    void Button4Click(object sender, EventArgs e)
    {
    rem();
    }
    void Button1Click(object sender, EventArgs e)
    {
    lower();
    }
    void Button2Click(object sender, EventArgs e)
    {
    upper();
    }
    void Button5Click(object sender, EventArgs e)
    {
    join();
    }
    void Button7Click(object sender, EventArgs e)
    {
    split();
    }
    void Button6Click(object sender, EventArgs e)
    {
    trim();
    }
    //display data 2
    void Button8Click(object sender, EventArgs e)
    {
    io();
    }
    void Button9Click(object sender, EventArgs e)
    {
    io2();
    }
    void Button10Click(object sender, EventArgs e)
    {
    lio();
    }
    void Button11Click(object sender, EventArgs e)
    {
    lio2();
    }
    //retry
    void Button12Click(object sender, EventArgs e)
    {
    this.textBox2.Clear();
    this.textBox3.Clear();
    this.textBox4.Clear();
    this.textBox5.Clear();
    this.textBox6.Clear();
    this.textBox7.Clear();
    this.textBox8.Clear();
    this.textBox9.Clear();
    this.textBox11.Clear();
    this.textBox12.Clear();
    this.textBox13.Clear();
    this.textBox14.Clear();
    this.textBox15.Clear();
    this.textBox16.Clear();
    this.textBox17.Clear();
    this.textBox18.Clear();
    this.textBox19.Clear();
    this.textBox20.Clear();
    this.textBox21.Clear();
    this.textBox22.Clear();
    this.textBox23.Clear();
    this.textBox24.Clear();
    this.textBox25.Clear();
    this.textBox26.Clear();
    this.textBox27.Clear();
    }
    //exit
    void Button16Click(object sender, EventArgs e)
    {
    this.Close();
    }
    }
    }
  4. setelah itu runningkan dan jalankan , amati cobalah mengerti sob :D
Sekian dari jufrikablog :D

No comments:

Post a Comment