0% found this document useful (0 votes)
71 views23 pages

Topik 4.3 Strings Method

This document discusses a Visual Basic .NET programming course that teaches string methods. The course aims to teach students how to create VB.NET applications and manipulate data. Topic 4.3 focuses on constructing programs using string methods like Len(), Mid(), Left(), Right(), Trim(), Replace(), and more. The document provides examples of using these string methods on sample strings and displaying the output.

Uploaded by

Pabbura_Hati
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views23 pages

Topik 4.3 Strings Method

This document discusses a Visual Basic .NET programming course that teaches string methods. The course aims to teach students how to create VB.NET applications and manipulate data. Topic 4.3 focuses on constructing programs using string methods like Len(), Mid(), Left(), Right(), Trim(), Replace(), and more. The document provides examples of using these string methods on sample strings and displaying the output.

Uploaded by

Pabbura_Hati
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

F5227 VISUAL BASIC .

NET PROGRAMMING

Topic 4.3 : Construct Program Using String Methods

Course Learning Outcome (CLO)


Upon completion of this course, students should be able to : 1. Create a simpe VB.NET based application based on the Windows Application template. 2. Describe on essential terminology including memory, data types and graphical user interface. 3. Apply object oriented programming techniques to create classes, add methods and add properties. 4. create a simple VB.NET based Web forms application that uses an XML Web Service and manipulate data in database by using Microsoft ADO.NET.

Course Learning Outcome:


Topic 4.0
1. Apply object oriented programming techniques to create classes, add methods and add properties. (CLO3)

Topic 4.0
Topic 4.1 : Use Classes, Object and Methods Topic 4.2 : Apply Inheritance And Polymorphism Topic 4.3 : Construct Program Using String Methods Topic 4.4 : Understand the concepts of Exception Handling

Introduction
The String Class represents character strings. The String data type comes from the System.String class . (System.Class) The String type represents a string of Unicode Characters . The String class is a sealed class , so you cannot inherit another class from the String class.

The String object is Immutable , it cannot be modified once it created, that means every time you use any operation in the String object , you create a new String Object . So if you are in a situation in continuous operation with String Object it is recommended to use System.Text.StringBuilder .

StringBuilder is a class which is used to handle strings. It Provides Some Standard Function like Append, Reverse, Remove and used for Mutable Strings. The StringBuilder class is defined in the System.Text namespace.

Example
Using StringBuilder class to append and replace function.

Imports System.Text Module Module1 Sub Main() Dim builder As New StringBuilder builder.Append("Rohatash") builder.Append("Kumar") Dim s As String = builder.ToString Console.WriteLine("This defines the append function:=" & s) builder.Replace("ha", "na") Dim m As String = builder.ToString Console.WriteLine("This defines the replace function:=" & m) Console.WriteLine("Length of string is:" + builder.Length.ToString()) End Sub End Module

Output

Strings Function
The Len Function
The length function is used to find out the number of characters in any given string.

Syntax
Len(string) Example Dim leng As String = Len(" Rohatash kumar") Console.WriteLine("length is :" & leng)

The Mid function


The mid function is used to Return a substring containing a specified number of characters from a string.

Syntax
Mid (string, start[, length])
string - String expression from which characters are returned. start - Long. Character position in string at which the part to be taken begins. length - Length is Optional. Number of characters to return.

Example
Dim middle As String = Mid("Rohatash Kumar", 3, 4) Console.WriteLine("Mid is :" & middle)

Output;??

The Left Function


The Left function extract the left portion of a string.

Syntax
Left("string", n)

Example
Dim leftf As String = Left("Rohatash Kumar", 3) Console.WriteLine("Left is:" & leftf)

The Right Function


The Right function extract the right portion of a string.

Syntax
Right("string", n)

Example
Dim rightr As String = Right("rohatash kumar", 6) Console.WriteLine("Right is :" & rightr)

The Space Function


The space function is used to Return a string containing the specified number of blank spaces.

Syntax
Space (number)

Example
Dim spaces As String = Right("rohatash kumar", 7) Console.WriteLine("Space is :" & spaces)

The Replace Function


The replace function is used to replacing some text in a string with some other text.

Syntax
Replace( string, searchtext, replacetext ) Example
Dim replaces As String = Replace("rohatash kumar", "hat", "nmo Console.WriteLine("Replace is :" & replaces)

The Trim function


The trim function trims the empty spaces on both side of the String.

Syntax
Trim ("String")

Example
Dim trimt As String = Trim(" rohatash kumar ") Console.WriteLine("Trim is :" & trimt)

The Ltrim Function


The Ltrim function trims the empty spaces of the left portion of the string.

Syntax
Ltrim("string")

Example
Dim ltriml As String = LTrim(" rohatash kumar Console.WriteLine("ltrim is :" & ltriml) ")

The Rtrim Function


The Rtrim function trims the empty spaces of the Right portion of the string.

Syntax
Rtrim("string")

Example
Dim rtrimr As String = RTrim(" rohatash kumar Console.WriteLine("rtrim is :" & rtrimr) ")

The Ucase and the Lcase Functions


The Ucase function converts all the characters of a string to capital letters. On the other hand, the Lcase function converts all the characters of a string to small letters.

Example
Dim ucaseu As String = UCase("rohatash kumar") Console.WriteLine("Ucase is :" & ucaseu) Dim lcasel As String = LCase("ROHATASH KUMAR") Console.WriteLine("Ucase is :" & lcasel)

Output:??

Module Module1 Sub Main() Dim leng As String = Len(" Rohatash kumar") Console.WriteLine("length is :" & leng) Dim middle As String = Mid("Rohatash Kumar", 3, 4) Console.WriteLine("Mid is :" & middle) Dim leftf As String = Left("Rohatash Kumar", 3) Console.WriteLine("Left is:" & leftf) Dim rightr As String = Right("rohatash kumar", 6) Console.WriteLine("Right is :" & rightr) Dim spaces As String = Right("rohatash kumar", 7) Console.WriteLine("Space is :" & spaces) Dim replaces As String = Replace("rohatash kumar", "hat", "nmo") Console.WriteLine("Replace is :" & replaces) Dim trimt As String = Trim(" rohatash kumar ") Console.WriteLine("Trim is :" & trimt) Dim ltriml As String = LTrim(" rohatash kumar ") Console.WriteLine("ltrim is :" & ltriml) Dim rtrimr As String = RTrim(" rohatash kumar ") Console.WriteLine("rtrim is :" & rtrimr) Dim ucaseu As String = UCase("rohatash kumar") Console.WriteLine("Ucase is :" & ucaseu) Dim lcasel As String = LCase("ROHATASH KUMAR") Console.WriteLine("Ucase is :" & lcasel) End Sub End Module

Output

You might also like