Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Working with string APIs
[ All Languages » VB »  String]

Total Hit ( 2360)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" ( _
    ByVal lpString1 As String, _
    ByVal lpString2 As String) As Long

Private Declare Function lstrcmp Lib "kernel32" Alias "lstrcmpA" ( _
    ByVal lpString1 As String, _
    ByVal lpString2 As String) As Long

Private Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" ( _
    ByVal lpString1 As String, _
    ByVal lpString2 As String) As Long

Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" ( _
    ByVal lpString1 As String, _
    ByVal lpString2 As String) As Long

Private Declare Function lstrcpyn Lib "kernel32" Alias "lstrcpynA" ( _
    ByVal lpString1 As String, _
    ByVal lpString2 As String, _
    ByVal iMaxLength As Long) As Long

Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" ( _
    ByVal lpString As String) As Long

Private Declare Function CharLowerBuff Lib "user32" Alias "CharLowerBuffA" ( _
    ByVal lpsz As String, _
    ByVal cchLength As Long) As Long

Private Declare Function CharUpperBuff Lib "user32" Alias "CharUpperBuffA" ( _
    ByVal lpsz As String, _
    ByVal cchLength As Long) As Long

Private Declare Function CharLower Lib "user32" Alias "CharLowerA" ( _
    ByVal lpsz As String) As Long

Private Declare Function CharUpper Lib "user32" Alias "CharUpperA" ( _
    ByVal lpsz As String) As Long

Private Declare Function IsCharAlpha Lib "user32" Alias "IsCharAlphaA" ( _
    ByVal cChar As Byte) As Long

Private Declare Function IsCharAlphaNumeric Lib "user32" Alias "IsCharAlphaNumericA" ( _
    ByVal cChar As Byte) As Long

Private Declare Function IsCharLower Lib "user32" Alias "IsCharLowerA" ( _
    ByVal cChar As Byte) As Long

Private Declare Function IsCharUpper Lib "user32" Alias "IsCharUpperA" ( _
    ByVal cChar As Byte) As Long

Private Sub Form_Load()
  Dim str1 As String, str2 As String
  Dim strTest As String
  '//Concate demo
  MsgBox ApiConcate("Hello ", "World"), , "Concate strings"

  '//String Copy demo
  str1 = "This is string to copy"
  Call ApiCopyString(str1, str2, 8)
  MsgBox str2, , "Copy string"

  '//To lower case demo
  MsgBox ApiDoLower("ABCDEFGHIJK", 5), , "Convert to lower case"

  '//To upper case demo
  MsgBox ApiDoUpper("abcdefghijk", 5), , "Convert to upper case"
End Sub

Function ApiConcate(str1 As String, str2 As String) As String
  Dim strTemp As String
  'Create a buffer with all Null char
  strTemp = String(lstrlen(str1) + lstrlen(str2), 0)

  'Append two strings
  lstrcat strTemp, str1
  lstrcat strTemp, str2

  ApiConcate = strTemp
End Function


Function ApiDoUpper(strSrc As String, Optional NChar As Long = 0) As String
  'Copy the string into the buffer
  If NChar = 0 Then
    ApiDoUpper = String(lstrlen(strSrc), 0)
    CharUpper strSrc
    ApiDoUpper = strSrc
  Else
    '//lower only n characters
    CharUpperBuff strSrc, NChar
    ApiDoUpper = strSrc
  End If
End Function

Function ApiDoLower(strSrc As String, Optional NChar As Long = 0) As String
  'Copy the string into the buffer
  If NChar = 0 Then
    ApiDoLower = String(lstrlen(strSrc), 0)
    CharLower strSrc
    ApiDoLower = strSrc
  Else
    '//lower only n characters
    CharLowerBuff strSrc, NChar
    ApiDoLower = strSrc
  End If
End Function

Function ApiCopyString(strSrc As String, strDest As String, Optional NChar As Long = 0)
  'Copy the string into the buffer
  If NChar = 0 Then
    strDest = String(lstrlen(strSrc), 0)
    lstrcpy strDest, strSrc
  Else
    strDest = String(NChar, 0)

    '//Copy only n characters
    lstrcpyn strDest, strSrc, NChar
  End If
End Function

Function ApiCompare(str1 As String, str2 As String, Optional IsCaseSensitive As Boolean = False) As Boolean
  '//////////////////////////////////////////////////////
  '//compare two string (case sensitive)
  '//////////////////////////////////////////////////////
  'Check if the strings are the same
  If IsCaseSensitive = True Then
    If lstrcmp(str1, str2) = 0 Then
      ApiCompare = True
    Else
      ApiCompare = False
    End If
  Else
    '//////////////////////////////////////////////////////
    '//compare two string (case in-sensitive)
    '//////////////////////////////////////////////////////
    If lstrcmpi(str1, str2) = 0 Then
      ApiCompare = True
    Else
      ApiCompare = False
    End If
  End If
End Function

Private Sub Form_KeyPress(KeyAscii As Integer)
  Dim strMsg As String

  'Get the character information
  If IsCharAlphaNumeric(KeyAscii) Then strMsg = " AlphaNumeric "
  If IsCharAlpha(KeyAscii) Then strMsg = "Alpha "
  If IsCharLower(KeyAscii) Then strMsg = strMsg + " Lower "
  If IsCharUpper(KeyAscii) Then strMsg = strMsg + " Upper "

  strMsg = "You pressed: " + Chr$(KeyAscii) & vbCrLf & "Key is >>" & strMsg
  MsgBox strMsg
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.