Important alert: (current site time 7/15/2013 8:44:57 AM EDT)
 

VB icon

an altenative code for substring function

Email
Submitted on: 12/3/2003 9:47:45 AM
By: barkýn ünüulu  
Level: Beginner
User Rating: By 1 Users
Compatibility: VB.NET
Views: 14888
author picture
(About the author)
 
     Purpose of this little code is to give an alternative to the substring function .NET uses. The code uses left and right functions of visual basic in order to find the substring of the entered string value... This is a console application.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: an altenative code for substring function
// Description:Purpose of this little code is to give an alternative to the substring function .NET uses.
The code uses left and right functions of visual basic in order to find the substring of the entered string value... This is a console application.
// By: barkýn ünüulu
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1860&lngWId=10//for details.//**************************************

Imports Microsoft.VisualBasic
Module Module1
Sub Main()
Dim f As New find_substring()
Dim newstring As String
Dim beginlength As Long
Dim lastlength As Long
Console.WriteLine("ENTER THE STRING VALUE SUBJECT TO BE TRIMMED")
newstring = Console.ReadLine
Console.WriteLine("ENTER THE BEGINING VALUE OF THE STRING")
beginlength = Console.ReadLine
Console.WriteLine("ENTER THE LAST VALUE OF THE STRING")
lastlength = Console.ReadLine
'Console.Write(f.katar(beginlength, lastlength, newstring))
Console.Out.WriteLine(f.katar(beginlength, lastlength, newstring))
Console.ReadLine()
End Sub
End Module
Public Class find_substring
Dim firstlength As Long
Dim secondlength As Long
Dim thirdlength As Long
'Dim a As String
Dim b As String
Dim c As String
Dim d As String
Public Function katar(ByVal beginning As Long, ByVal ending As Long, ByVal a As String) As String
firstlength = Len(a)
secondlength = firstlength - (beginning - 1)
b = Right(a, secondlength)
c = Left(b, ending)
Return c
End Function
End Class


Other 12 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

8/10/2004 5:02:21 AMPaul Stevens

interesting except that what you are now doing is calling vb's Left and Right functions which in turn call Substring, insteaf of calling Substring.

For Example, this is roughly what VB's Right function Looks like

Public Shared Function Right(ByVal str As String, ByVal Length As Integer) As String
If (Length < 0) Then
Throw New ArgumentException(Utils.GetResourceString("Argument_GEZero1", "Length"))
End If
If ((Length = 0) OrElse (str Is Nothing)) Then
Return ""
End If
Dim num1 As Integer = str.Length
If (Length >= num1) Then
Return str
End If
Return str.Substring((num1 - Length), Length)
End Function

notice the call to substring



(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.