Pages

sexta-feira, 14 de outubro de 2011

Vb.net strings

HhhO tipo de dado Strings é implementado no VB.NET com uma classe e não como uma estrutura e isto trouxe muitas implicações expandindo em muito as possibilidades de tratar e trabalhar com Strings.

Podemos definir Strings no VB.NET como  uma representação imutável de caracteres.

3- Procurando uma string/substring dentro de outra string - IndexOf

IndexOf - método publico que retorna a posição de uma string/substring dentro de outra string.

Os métodos sobrecarregados são : (para saber mais leia o artigo - VB.NET - Conceitos : Sobrecarga (Overloading)< )

         Overloads Public Function IndexOf(Char) As Integer : retorna o índice da primeira ocorrência do caracter Unicode na string

         Overloads Public Function IndexOf(String) As Integer : retorna o índice da primeira ocorrência da string na instância.

         Overloads Public Function IndexOf(Char, Integer) As Integer : retorna o índice da primeira ocorrência do caracter Unicode na string . A procura começa pela posição do caractere definido.

         Overloads Public Function IndexOf(String, Integer) As Integer : retorna o índice da primeira ocorrência da string na instância. A procura começa pela posição do caractere definido.

         Overloads Public Function IndexOf(Char, Integer, Integer) As Integer : retorna o índice da primeira ocorrência do caractere na instância. A procura começa pela posição do caractere definido e examina um número definido de posições de caracteres.

         Overloads Public Function IndexOf(String, Integer, Integer) As Integer : retorna o índice da primeira ocorrência da string na instância. A procura começa pela posição do caractere definido e examina um número definido de posições de caracteres.

Vejamos um exemplo :


Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim nome As String = "Jessica Naara Macoratti"

Dim posicao As Integer

posicao = nome.IndexOf("Naara")             'retorna 8 pois Naara tem inicio na posição 8 da string nome

posicao = nome.IndexOf("M")                   'retorna 14 que indica a posição da letra M na string

posicao = nome.IndexOf("a", 7)                'retorna 9 que é a posição da primeira letra 'a' após a sétima posição

posicao = nome.IndexOf("ra", 5)               'retorna 11 que indica posição de inicio da string 'ra' a partir da posição 5

End Sub

4- Procurando e substituindo texto em uma string - Replace

Replace - Este método procura por um texto/caractere específico em uma string e o substitui por outro texto/caractere indicado.

Os métodos sobrecarregados são :

Overloads Public Function Replace(Char, Char) As String -  Substitui todas as ocorrências do caracter Unicode especificado na String pelo caractere Unicode definido.

Overloads Public Function Replace(String, String) As String - Substitui todas as ocorrências do String Unicode especificado na String pela String  Unicode definido.

Exemplo :
Dim texto As String = " Nossa ! como esta calor "

texto = texto.Replace("!", "!!!")

texto = texto.Replace("calor", "frio")

MsgBox(texto, MsgBoxStyle.Information)


- Neste exemplo primeiro substituímos o caractere ! por !!!

- A seguir substituímos a string 'Calor' pela string 'frio'

- Exibimos o resultado com um msgbox - Nossa !!! como esta frio

5 - Convertendo uma string para Caixa Alta e/ou Caixa Baixa - ToUper/ToLower

- Convertendo para caixa alta  - ToUpper

Overloads Public Function ToUpper() As String - Retorna uma copia da String em caixa alta.

Overloads Public Function ToUpper(CultureInfo) As String - Retorna uma copia da String em caixa alta , levando em consideração a informação especifica da cultura.

Convertendo para caixa baixa:  ToLower

Overloads Public Function ToLower() As String - Retorna uma copia da String em caixa baixa

Overloads Public Function ToLower(CultureInfo) As String - Retorna uma copia da String em caixa baixa , levando em consideração a informação especifica da cultura.

1 - Obtendo o tamanho(comprimento) de uma String - Length

Length - Esta propriedade retorna o número de caracteres em uma string . Código exemplo :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim nome As String = "José Carlos Macoratti"

Dim tamanho As Integer

tamanho = nome.Length

MsgBox("O número de caracteres em nome é : " & tamanho, MsgBoxStyle.Information, "Length")

End Sub

Observe a sintaxe usada :   string.propriedade  (a sintaxe é válida para as demais propriedades/métodos)

Vb.net Substrings

Substring

Another useful string method is Substring. This allows you to grab one string within another. (For example, if you wanted to grab the ".com" from the email address "me@me.com")

In between the round brackets of Substring( ), you specify a starting position, and then how many characters you want to grab (the count starts at zero again). Like this:

Dim Email as String
Dim DotCom as String

Email = "me@me.com"
DotCom = Email.Substring(5, 4)

MsgBox(DotCom)

The message box would then display the characters grabbed from the string, in this case the ".com" at the end (start at position 5 in the string and grab 4 characters).

You could also do a check to see if an email address ended in ".com" like this:

Dim Email As String
Dim DotCom As String

Email = "me@me.con"
DotCom = Email.Substring(Email.Length - 4, 4)

If DotCom = ".com" Then
MsgBox("Ends in Dot Com")
Else
MsgBox("Doesn't End in Dot Com")
End If

The starting position for Substring( ) this time is "Email.Length - 4". This is the length of the string variable called Email, minus 4 characters. The other 4 means "grab four characters"

You have to be careful, though. If there wasn't four characters to grab, VB would give you an error message.

We could replace the Chars() For loop code we wrote earlier with a Substring() method. The result would be the same. Here's the code:

For i = 0 To TextLength - 1
OneCharacter = FirstName.Substring(i, 1)
MsgBox OneCharacter
Next i

So we're saying, "Start grabbing characters from the position i. Just grab one character".

Substring and Chars are very useful methods to use when you want to check the letters in a string of text.

quinta-feira, 13 de outubro de 2011

Multimídia e Animação - Adobe Flash - Aula 1

http://active.tutsplus.com/tutorials/animation/animate-an-explosion-with-flash-professional/

MySQL Database - First Class





O MySQL é um SGBD (Sistema de Gerenciamento de Banco de Dados), que utiliza a linguagem SQL (Linguagem de Consulta Estruturada, do inglês Structured Query Language) como interface. Em nossos dias é um dos SGBD mais utilizados com mais de 10 milhões de cópias instaladas em todo o mundo, inclusive em grandes empresas.

Vantagens do MySQL:
Portabilidade (multiplataforma);
Compatibilidade (drivers ODBC, JDBC e .NET; módulos de interface para várias linguagens de programação: Delphi, Java, C/C++, C#, Visual Basic, Python, Perl, PHP, ASP e Ruby);
Excelente desempenho, estabilidade e usabilidade;
Pouco exigente quanto a recursos de hardware;
É um Software Livre;
Contempla a utilização de vários Storage Engines como MyISAM, InnoDB, Falcon, BDB, Archive, Federated, CSV, Solid;
Suporta controle transacional;
Suporta Triggers;
Suporta Cursors (Non-Scrollable e Non-Updatable);
Suporta Stored Procedures e Functions;
Replicação facilmente configurável;
Interfaces gráficas (MySQL Toolkit) de fácil utilização cedidos pela MySQL Inc.


Mais especificamente, o que é SQL?

É uma linguagem Structured Query Language
SQL lets you access and manipulate databases
SQL is an ANSI (American National Standards Institute) standard

What Can SQL do?

SQL can execute queries against a database
SQL can retrieve data from a database
SQL can insert records in a database
SQL can update records in a database
SQL can delete records from a database
SQL can create new databases
SQL can create new tables in a database
SQL can create stored procedures in a database
SQL can create views in a database
SQL can set permissions on tables, procedures, and views

SQL is a Standard - BUT....

Although SQL is an ANSI (American National Standards Institute) standard, there are many different versions of the SQL language.

However, to be compliant with the ANSI standard, they all support at least the major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar manner.

Note: Most of the SQL database programs also have their own proprietary extensions in addition to the SQL standard!
Using SQL in Your Web Site

To build a web site that shows some data from a database, you will need the following:

An RDBMS database program (i.e. MS Access, SQL Server, MySQL)
A server-side scripting language, like PHP or ASP
SQL
HTML / CSS

RDBMS

RDBMS stands for Relational Database Management System.

RDBMS is the basis for SQL, and for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.

The data in RDBMS is stored in database objects called tables.

A table is a collection of related data entries and it consists of columns and rows.






web hosting

quarta-feira, 12 de outubro de 2011

Banco de Dados MySQL - Aula 3

This chapter will explain the SELECT and the SELECT * statements.
The SQL SELECT Statement

The SELECT statement is used to select data from a database.

The result is stored in a result table, called the result-set.
SQL SELECT Syntax
SELECT column_name(s)
FROM table_name

and
SELECT * FROM table_name

Note Note: SQL is not case sensitive. SELECT is the same as select.
An SQL SELECT Example

The "Persons" table:
P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger

Now we want to select the content of the columns named "LastName" and "FirstName" from the table above.

We use the following SELECT statement:
SELECT LastName,FirstName FROM Persons

The result-set will look like this:
LastName FirstName
Hansen Ola
Svendson Tove
Pettersen Kari

SELECT * Example

Now we want to select all the columns from the "Persons" table.

We use the following SELECT statement:
SELECT * FROM Persons

Tip: The asterisk (*) is a quick way of selecting all columns!

The result-set will look like this:
P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger

Navigation in a Result-set

Most database software systems allow navigation in the result-set with programming functions, like: Move-To-First-Record, Get-Record-Content, Move-To-Next-Record, etc.

Programming functions like these are not a part of this tutorial. To learn about accessing data with function calls, please visit our ADO tutorial or our PHP tutorial.

web hosting

Banco de Dados MySQL - Aula 2

Database Tables

A database most often contains one or more tables. Each table is identified by a name (e.g. "Customers" or "Orders"). Tables contain records (rows) with data.

Below is an example of a table called "Persons":
P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger

The table above contains three records (one for each person) and five columns (P_Id, LastName, FirstName, Address, and City).
SQL Statements

Most of the actions you need to perform on a database are done with SQL statements.

The following SQL statement will select all the records in the "Persons" table:
SELECT * FROM Persons

In this tutorial we will teach you all about the different SQL statements.
Keep in Mind That...

SQL is not case sensitive

Semicolon after SQL Statements?

Some database systems require a semicolon at the end of each SQL statement.

Semicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL statement to be executed in the same call to the server.

We are using MS Access and SQL Server 2000 and we do not have to put a semicolon after each SQL statement, but some database programs force you to use it.
SQL DML and DDL

SQL can be divided into two parts: The Data Manipulation Language (DML) and the Data Definition Language (DDL).

The query and update commands form the DML part of SQL:

SELECT - extracts data from a database
UPDATE - updates data in a database
DELETE - deletes data from a database
INSERT INTO - inserts new data into a database

The DDL part of SQL permits database tables to be created or deleted. It also defines indexes (keys), specifies links between tables, and imposes constraints between tables. The most important DDL statements in SQL are:

CREATE DATABASE - creates a new database
ALTER DATABASE - modifies a database
CREATE TABLE - creates a new table
ALTER TABLE - modifies a table
DROP TABLE - deletes a table
CREATE INDEX - creates an index (search key)
DROP INDEX - deletes an index

web hosting

terça-feira, 11 de outubro de 2011

Banco de Dados MySQL - Aula 1




O MySQL é um SGBD (Sistema de Gerenciamento de Banco de Dados) que utiliza a linguagem SQL (Linguagem de Consulta Estruturada, do inglês Structured Query Language) como interface. Especificamente, é um Sistema de Gerenciamento de Banco de Dados Relacional. Em nossos dias é um dos SGBD mais utilizados com mais de 10 milhões de cópias instaladas em todo o mundo, inclusive em grandes empresas.

Vantagens do MySQL:
Portabilidade (multiplataforma);
Compatibilidade (drivers ODBC, JDBC e .NET; módulos de interface para várias linguagens de programação: Delphi, Java, C/C++, C#, Visual Basic, Python, Perl, PHP, ASP e Ruby);
Excelente desempenho, estabilidade e usabilidade;
Pouco exigente quanto a recursos de hardware;
É um Software Livre;
Contempla a utilização de vários Storage Engines como MyISAM, InnoDB, Falcon, BDB, Archive, Federated, CSV, Solid;
Suporta controle transacional;
Suporta Triggers;
Suporta Cursors (Non-Scrollable e Non-Updatable);
Suporta Stored Procedures e Functions;
Replicação facilmente configurável;
Interfaces gráficas (MySQL Toolkit) de fácil utilização cedidos pela MySQL Inc.


Mais especificamente, o que é SQL?

É uma linguagem de consulta de Banco de Dados, baseada na Teoria dos Conjuntos, pertence ao padrão ANSI (American National Standards Institute). O SQL permite a extração de dados de sua base pela interpretação de linguagem lógica e estruturada - Structured Query Language.
O que o SQL pode fazer?

O SQL executa funções em um Banco de Dados; cria tabelas; bases; insere, atualiza e deleta informações. SQL can create stored procedures in a database
SQL can create views in a database
SQL can set permissions on tables, procedures, and views

SQL is a Standard - BUT....

Although SQL is an ANSI (American National Standards Institute) standard, there are many different versions of the SQL language.

However, to be compliant with the ANSI standard, they all support at least the major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar manner.

Note: Most of the SQL database programs also have their own proprietary extensions in addition to the SQL standard!
Using SQL in Your Web Site

To build a web site that shows some data from a database, you will need the following:

An RDBMS database program (i.e. MS Access, SQL Server, MySQL)
A server-side scripting language, like PHP or ASP
SQL
HTML / CSS

RDBMS

RDBMS stands for Relational Database Management System.

RDBMS is the basis for SQL, and for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.

The data in RDBMS is stored in database objects called tables.

A table is a collection of related data entries and it consists of columns and rows.



web hosting