segunda-feira, 12 de agosto de 2019

C# - convertendo string num array de string

Aqui está um exemplo de como converter uma string
num array de string.

Veja abaixo uma imagem do programa em execução:



Veja abaixo o código do programa:


//C# - CONVERTENDO STRING NUM ARRAY DE STRING
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Arr {

    public partial class Form1 : Form {
        System.Text.StringBuilder str_1 = new System.Text.StringBuilder ( );
        string st = " ";
        /*============================================================*/
        void Informe ( PaintEventArgs e ) {
            Graphics dc = e.Graphics;
            Font myFont = new System.Drawing.Font ( "Helvetica", 11,
                FontStyle.Italic );
            Brush myBrush_1 = new SolidBrush ( System.Drawing.Color.Red );
            Brush myBrush_2 = new SolidBrush ( System.Drawing.Color.Blue );
            Brush myBrush_3 = new SolidBrush ( System.Drawing.Color.Black );
            dc.DrawString ( "Por: ", myFont, myBrush_1, 170, 210 );
            dc.DrawString ( "Samuel Lima ", myFont, myBrush_2, 200, 210 );
            dc.DrawString ( "sa_sp10@hotmail.com ", myFont, myBrush_3, 170, 225 );
        }
        /*============================================================*/
        public void Ini_Array ( ) {
            int i = 0;
            do {
                if ( i % 10 == 0 ) {
                    st += "\n";
                }
                if ( i >= 0 && i <= 9 )
                    st += ( "0" );
                st += i + " ";
                i++;
            } while ( i < 100 );
            string [ ] strBd = new string [ 10 ];
            i = 0;
            strBd [ i ] = st;
            str_1.Append ( strBd [ i ] );
        }
        /*============================================================*/
        protected override void OnPaint ( PaintEventArgs e ) {
            this.Size = new System.Drawing.Size ( 600, 300 );
            this.Text = "C# - CONVERTENDO STRING NUM ARRAY DE STRING";
            this.BackColor = Color.LightGray;
            Graphics dc = e.Graphics;
            Pen BluePen = new Pen ( Color.Blue, 10 );
            dc.DrawRectangle ( BluePen, 5, 5, 575, 250 );
            Font myFont_1 = new System.Drawing.Font ( "Consolas", 12,
                FontStyle.Italic );
            Font myFont_2 = new System.Drawing.Font ( "Consolas", 11,
                FontStyle.Italic );
            Brush myBrush_1 = new SolidBrush ( Color.Red );
            Brush myBrush_2 = new SolidBrush ( Color.Black );
            dc.DrawString ( "C# - CONVERTENDO STRING NUM ARRAY DE STRING",
                myFont_1, myBrush_1, 100, 15 );
            dc.DrawString ( " " + str_1, myFont_2, myBrush_2, 170, 20 );
            Informe ( e );
        }
        /*============================================================*/
        public Form1 ( ) {
            Ini_Array ( );
        }
    }
    /*============================================================*/
    static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main ( ) {
            Application.EnableVisualStyles ( );
            Application.SetCompatibleTextRenderingDefault ( false );
            Application.Run ( new Form1 ( ) );
        }
    }
}

Nenhum comentário:

Postar um comentário