School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,363 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,430 people online right now. Registration is fast and FREE... Join Now!




VB6 - Understanding Basic String Operations

 
Reply to this topicStart new topic

> VB6 - Understanding Basic String Operations, Play with Words, Simple!

Nikhil_07n
Group Icon



post 25 Jan, 2009 - 07:11 AM
Post #1


The string Functions allows us to work with strings, as it's clear from their name.

1) Lcase and Ucase Functions

Explanation : Converts string to Lower and Upper case respectively.

Syntax :

CODE


LCase(String)

UCase(String)



Example :

CODE


Print Lcase("NiKhIl")

' The Output is : 'nikhil'

Print UCase("grEen")

' The Output is : 'GREEN'



2) Len Function

Explanation : Returns length of string, simple.

Syntax:

CODE


Len(String)



Example:

CODE


Print Len("Green Day")

'The Output is 9



3) Trim, Ltrim , Rtrim

(i) Trim - Removes Leading and trailing spaces.
(ii) Ltrim - Removes leading spaces.
(iii) Rtrim - Removes trailing spaces.

NOTE : all of these DO NOT effect spaces BETWEEN the words.

Syntax:

CODE


Ltrim(String)
Rtrim(String)
Trim(String)



Example:

CODE


Print Trim("   Beautiful Day     ")

'Output is 'Beautiful Day'

Print Ltrim("   Beautiful Day   ")

'Output is 'Beautiful Day   '

Print Rtrim("   Beautiful Day   ")

'Output is '   Beautiful Day'

'IMP: Carefully notice the spaces in OUTPUTs.


4) Left And right functions:

Explanation : Extracts some no. of characters from LEFTMOST and RIGHTMOST portion of a string respectively.

Syntax:

CODE


Left(String, Number-Of-Chars)
RIght(String, Number-Of-Chars)



Example:

CODE


Print Left("The Offspring Rocks",5)

' Output is 'The O'

Print Right("The Offspring Rocks",4)

'Output is 'ocks'



5)Mid Function

Explanation : Extracts some character from ANY portion of the string.

Syntax:

CODE


MID(String, Start-Position, Number-Of-Chars)



Example:

CODE


Print MID("Basket Case",3,2)

' The Output is 'sk'



6) Instr Fuction

Explanation : THis function searches string within strings, i.e., returns location of a string within string.

Syntax :

CODE


Instr(start-postion, string-in-which-searchin, string-to-search-for)



Explanation :

CODE


Print InStr(1, "Brain Stew", "ain")

' The OutPut is 3



7) Space Function

Explanation : Produces Number of Spaces, easy.

Syntax:

CODE


Space(no-of-spaces-to-be-generated)



Example:

CODE


Print "Hi" & Space(5) & "There"

'Output is 'Hi     There'



8) String Function

Explanation : Generate particular no of characters.

Syntax :

CODE


String(number-of-times, character)



Example :

CODE


Print String(10, "A")

'The Output is 'AAAAAAAAAA'



9) Str Function

Explanation : Converts a number in equivalent string.

Syntax:

CODE


Str(number)



Example :

CODE


Print Str(-155)

'Output is "-155"



10) Asc Function

Explanation : Returns Ascii code of a character.

Syntax:

CODE


Asc(String)



Example:

CODE


Asc("F")

'Output is 70

Asc("Dessloch")

'Output is 68 as ascii code of "D" is 68

'NOTE: In multi charactered string, it prints ascii code of first letter without any error



10) StrReverse Function

Explanation : Returns the string, INVERTED.

Syntax:

CODE


StrReverse(String)



Example:

CODE


StrReverse("ABCD")

'Output is 'DCBA'



=============END================

whoa, lots of Typing!
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

The Gothic
*



post 8 Jun, 2009 - 01:16 AM
Post #2
Thx a lot, itīs very usefull for novice like me blink.gif

This post has been edited by The Gothic: 8 Jun, 2009 - 01:17 AM
Go to the top of the page
+Quote Post


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/7/09 08:36PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month