Thursday 7 November 2013

C# chapter 5 : C# or C sharp For Beginer, Working with Text

C# chapter 5 :


For any one that have not read chapter 1 , 2  , 3 & 4 ,
Please refer C#  chapter 1 , 2  , 3 & 4   if have any question.

OK!  Let continue !

Working with Text



Find & Deleting part of the line




Must  Remember  This
Line count start from 0, so if Line is:  ABCD
A=0 , B=1 , C=2 , D=3
Line count start from 0


//
is use for reminder note only , any things after //  in the same line will not have any effect !
example 1 :
string STR_A;    // declared  that STR_A will be String

example 2 :
int INT_A;    // declared  that INT_A will be integer (number)

example 3 :
string STR_A, STR_B, STR_C;       // declared  that STR_A will be String
                                                       // declared  that STR_B will be String
                                                      // declared  that STR_C will be String 


___________________________________________


Find & Deleting part of the line

C#   code:

        private void button1_Click(object sender, EventArgs e)
        {
            string STR_A, STR_B, STR_C;
            int INT_A;
            STR_A = "abcdefgh";
            textBox1.Text = STR_A;
            INT_A = STR_A.IndexOf("cde");                    // find  cde
            STR_B = STR_A.Remove(INT_A, 3);
            textBox1.Text = textBox1.Text + "\r\n" + "\r\n" + STR_B;

        }


THEN  Select  Debug -> Start without Debugging
~  ~ Wait for a while  ~ ~ ~
The program Form screen will come out.
Let  click on button1
      abcdefgh
      abfgh
will show up  inside the Textbox.

Explanation :
IndexOf("???")
??? = the string of character you want to find, can be single character like "A"  or
          many character like " ABCD "

IndexOf("???")  will give an answer in integer, this is the starting position in the line for the
string of character you want to find

so to find "cde"  in  "abcdefgh"   the answer is 2 for c . c is the 1st in "cde"
STR_A = "abcdefgh";
INT_A = STR_A.IndexOf("cde"); 

so  INT_A  will be 2.


STR_B = STR_A.Remove(INT_A, 3);
Remove(x, y)
x =  start from ?
y =  How many character to be delete
for the program above
So this will be start at 3rd position in the line , delete 3 character
" c "  is the one at the 3rd position in line , delete 3 character , so  "cde"   had been deleted.
abcdefgh      become      abfgh

Must Remember This :   Line count start from 0, so if Line is:  ABCD
   A=0 , B=1 , C=2 , D=3 



Example 2  ,   C#   code:

        private void button1_Click(object sender, EventArgs e)
        {
            string STR_A, STR_B;
            int INT_A;
            STR_A = "abcdefgh";
            textBox1.Text = STR_A;
            INT_A = STR_A.IndexOf("cdef");                    // find  cdef
            STR_B = STR_A.Remove(INT_A + 1, 2);
            textBox1.Text = textBox1.Text + "\r\n" + "\r\n" + STR_B;
        }

THEN  Select  Debug -> Start without Debugging
~  ~ Wait for a while  ~ ~ ~
The program Form screen will come out.
Let  click on button1
      abcdefgh
      abcfgh
will show up  inside the Textbox.

Explanation :
IndexOf("???")
??? = the string of character you want to find, can be single character like "A"  or
          many character like " ABCD "

IndexOf("???")  will give an answer in integer, this is the starting position in the line for the
string of character you want to find

so to find "cdef"  in  "abcdefgh"   the answer is 2 for c . c is the 1st in "cdef"
STR_A = "abcdefgh";
INT_A = STR_A.IndexOf("cdef"); 

so  INT_A  will be 2.




STR_B = STR_A.Remove(INT_A + 1, 2);
Remove(x, y)
x =  start from ?
y =  How many character to be delete
for the program above
So this will be start at  INT_A + 1   position in the line
 INT_A is 2 , so  INT_A + 1   = 2+1  the answer is 3
Line count start from 0
So this will be start at  4th position in the line , delete 2 character
" d "  is the one at the 4th position in line , delete 2 character , so  "de"   had been deleted.
abcdefgh      become      abcfgh

Must Remember This :   Line count start from 0, so if Line is:  ABCD
   A=0 , B=1 , C=2 , D=3 





            STR_A = "abcdefgh";

            INT_A = STR_A.IndexOf("cdef");                    // find  cdef
            STR_B = STR_A.Remove(INT_A + 1, 2);

 abcdefgh      become      abcfgh

From this you can see that ,
you search for "cdef" but you only delete part of it "de"

Remove(INT_A + 3, 2)
Remove(INT_A - 1, 5)
You can change the plus (+)  to minus(-) , use it to delete part of line you don't want.

            STR_A = "abcdefgh";
            INT_A = STR_A.IndexOf("cdef");                    // find  cdef
            STR_B = STR_A.Remove(INT_A + 3, 2);
abcdefgh      become        abcdeh

            STR_A = "abcdefgh";
            INT_A = STR_A.IndexOf("cdef");                    // find  cdef
            STR_B = STR_A.Remove(INT_A - 1, 5) ;
abcdefgh      become        agh



___________________________________________
Need More Detail ?   contact me !!
Please send me some money at  Paypal
Any small amount is welcome , even 10 cents is good for me.

I will guide you step by step, personally.
My Paypal Account is :   ksw.industries@gmail.com

Don't know how to send money ?   Click here for detail about Paypal account.
http://xyberpast.blogspot.com/2014/05/how-to-get-my-program.html

Don't have money? OK! Here is another way to get the program.
http://xyberpast.blogspot.com/2014/05/how-to-get-my-program.html

Strong Lift Wear

No comments:

Post a Comment