Current area: HOME ->

Zip File view

string v1.0


This page allows you to view the contents of a file contained inside a ZIP archive available at Programmer's Heaven. This means you can view the code and find what you need from it without having to download the ZIP file first. If the file contains source code for a language we recognize, we have syntax highlighted it.

Filename displayed: String.bas
Found in file: string.zip

Download: Programming Arcade Games Is a tutorial on programming object oriented arcade games in  Turbo C.
Attribute VB_Name = "String"
OPTION Explicit
'Collected and created by Win Swarr [[Email Removed]]


Public FUNCTION reversestring(revstr AS STRING) AS STRING
      ' revstr: String to reverse
      ' Returns: The reverse string

      DIM doreverse AS LONG

      reversestring = ""
      FOR doreverse = LEN(revstr) TO 1 STEP -1
            reversestring = reversestring & MID$(revstr, doreverse, 1)
      NEXT

END FUNCTION

Public FUNCTION FindDelimitor(SearchString AS STRING, _
    Optional TokenList AS STRING = " " & vbTab) AS INTEGER

'Find the position of the first token delimitor character in a string.
'This function takes the following arguments:
'1 - The string to be searched
'2 - A list of token delimitors.
'    If this string is ommited the delimitors are set to " " and vbTab
'The function returns the position of the found character or
'zero if the character was not found


DIM StringLength AS INTEGER
DIM Counter AS INTEGER

StringLength = LEN(SearchString)
FOR Counter = 1 TO StringLength
  IF INSTR(TokenList, MID$(SearchString, Counter, 1)) > 0 THEN
    FindDelimitor = Counter
    EXIT FUNCTION
  END IF
NEXT
FindDelimitor = 0
END FUNCTION

'Find the position of the first character, which is NOT a token delimitor character, in a string.
'This function takes the following arguments:
'1 - The string to be searched
'2 - A list of token delimitors.
'    If this string is ommited the delimitors are set to " " and vbTab
'The function returns the position of the found character or
'zero if the character was not found

Public FUNCTION skipDelimitor(SearchString AS STRING, _
    Optional TokenList AS STRING = " " & vbTab) AS INTEGER

DIM StringLength AS INTEGER
DIM Counter AS INTEGER

StringLength = LEN(SearchString)
FOR Counter = 1 TO StringLength
  IF INSTR(TokenList, MID$(SearchString, Counter, 1)) = 0 THEN
    skipDelimitor = Counter
    EXIT FUNCTION
  END IF
NEXT
skipDelimitor = 0

END FUNCTION
FUNCTION FormatStringForSQLInsertStatment(ByRef szLine AS STRING, szTarget AS STRING, _
szReplacement AS STRING, szNumberColumns AS STRING) AS STRING

    DIM i AS INTEGER
    DIM j AS INTEGER
    DIM k AS INTEGER
    DIM c AS STRING
    DIM N AS INTEGER
    DIM szTemp AS STRING
    DIM szResult AS STRING
   
    ON ERROR RESUME NEXT
   
    szResult = szLine
    i = k = 2
    szResult = ReplaceEachStringWithString(szResult, szTarget, szReplacement)
   
    i = LEN(szNumberColumns) + 1
    j = i
    k = 1
    DO WHILE i >= 0
   
        'Get Number before first comma
        i = i - 1
        szTemp = Trim(Mid(szNumberColumns, (i), 1))
        IF szTemp = Trim(",") OR i = 0 THEN
            c = Trim(Mid(szNumberColumns, (i + 1), (k - 1)))
            N = (VAL(c))
            szResult = ReplaceNthStringWithString(szResult, ",'", ",", (N - 1))
            szResult = ReplaceNthStringWithString(szResult, "',", ",", N)
            j = i - 1
            k = 0
        END IF
        k = k + 1
    LOOP
   
    'Check for quote on left most portion of string
    IF Trim(Left(szNumberColumns, 1)) = "1" THEN
        IF Trim(Left(szResult, 2)) = ",'" OR Trim(Left(szResult, 2)) = "'," THEN
            szResult = Right(szResult, LEN(Trim(szResult)) - 2)
        ELSEIF Trim(Left(szResult, 1)) = "," OR Trim(Left(szResult, 1)) = "'" THEN
            szResult = Right(szResult, LEN(Trim(szResult)) - 1)
        END IF
    ELSE
        IF Trim(Left(szResult, 2)) = ",'" OR Trim(Left(szResult, 2)) = "'," THEN
            szResult = "'" + Right(szResult, LEN(Trim(szResult)) - 2)
        ELSEIF Trim(Left(szResult, 1)) <> "'" THEN
            szResult = "'" + szResult
        END IF
    END IF
   
    szLine = szResult
   
END FUNCTION
FUNCTION REMoveNthOccurenceOfString(ByRef szOriginal As String, szTarget As String, _
N AS INTEGER) AS INTEGER
'This function will remove the Nth occurence only of the target string
'within the original
   
    DIM i AS INTEGER
    DIM szTemp AS STRING
    DIM szResult AS STRING
    DIM j AS INTEGER
    DIM k AS INTEGER
    i = j = k = 0
   
    szTemp = szOriginal
   
    i = INSTR(1, szTemp, szTarget)
    DO WHILE k < N AND i > 0
        IF Mid(szOriginal, i, LEN(szTarget)) = szTarget THEN
            k = k + 1
            j = i
            i = INSTR(i, szTemp, szTarget)
            i = (i + LEN(szTarget))

        ELSE
            i = i + 1
        END IF
    LOOP
    i = j
    IF (i > 0) AND (k = N) THEN
        j = (i - 1)
        k = (i - 2)
        szTemp = Left(szTemp, j) + Right(szTemp, (LEN(szTemp) - (k + LEN(szTarget))) - 1)
        REMoveNthOccurenceOfString = i
    ELSE
        REMoveNthOccurenceOfString = 0
    END IF
   
    szOriginal = szTemp

END FUNCTION
FUNCTION REMoveString(ByRef szOriginal As String, szTarget As String) As Integer
'This function will remove the first occurence of the target string from
'the original, concatenating the string at the the leading and following
'characters
    DIM i AS INTEGER
    DIM szTemp AS STRING
    DIM szResult AS STRING
    DIM j AS INTEGER
    DIM k AS INTEGER
    i = j = k = 0
   
    szTemp = szOriginal
   
    i = INSTR(1, szTemp, szTarget)
    IF i > 0 THEN
        j = (i - 1)
        k = (i - 2)
        szTemp = Left(szTemp, j) + Right(szTemp, (LEN(szTemp) - (k + LEN(szTarget))) - 1)
        REMoveString = i
    ELSE
        REMoveString = 0
    END IF
   
    szOriginal = szTemp
   
END FUNCTION
FUNCTION ReplaceNthStringWithString(szOriginal AS STRING, szTarget AS STRING, _
szReplacement AS STRING, N AS INTEGER) AS STRING
'This function replaces the Nth instance only of a given string within
'the original with the replacement string.
    DIM i AS INTEGER
    DIM szTemp AS STRING
    DIM szResult AS STRING
    DIM j AS INTEGER
    DIM k AS INTEGER
    i = j = k = 0
   
    szResult = ""
    szTemp = szOriginal
   
    IF N > 0 THEN
       
        i = REMoveNthOccurenceOfString(szTemp, szTarget, N)
       
        szTemp = InsertString(szTemp, szReplacement, i)
   
    END IF
   
    ReplaceNthStringWithString = szTemp

END FUNCTION
FUNCTION ReplaceEachStringWithString(szOriginal AS STRING, szTarget AS STRING, szReplacement AS STRING) AS STRING
'This function replaces each instance of a given string within the
'original with the replacement string.
    DIM i AS INTEGER
    DIM szTemp AS STRING
    DIM szResult AS STRING
    DIM j AS INTEGER
    i = j = 0
    szResult = ""
    szTemp = szOriginal
    i = REMoveString(szTemp, szTarget)
    DO WHILE i > 0
        szTemp = InsertString(szTemp, szReplacement, i)
        i = REMoveString(szTemp, szTarget)
    LOOP
   
    ReplaceEachStringWithString = szTemp

END FUNCTION
FUNCTION InsertString(szSource AS STRING, szNew AS STRING, index) AS STRING
'This function will insert szNew before the character at index in the
'Source string
   
    DIM szResult AS STRING
    ON ERROR RESUME NEXT
   
    szResult = ""
    IF index > (LEN(szSource) + 1) THEN
        InsertString = szSource + Space(index - LEN(szSource)) + szNew
        EXIT FUNCTION
    END IF
    IF index = 0 THEN index = 1
    szResult = Left(szSource, (index - 1)) + szNew + Right(szSource, (LEN(szSource) - index) + 1)
   
    InsertString = szResult
   
END FUNCTION
FUNCTION ReplaceEachInstanceOfCharacter(szOriginal AS STRING, oldcharacter AS STRING, newcharacter AS STRING) AS STRING
'This function will replace any instance of a given character within the original string
    DIM i AS INTEGER
    DIM szTemp AS STRING
    DIM szResult AS STRING
    DIM j AS INTEGER
    DIM k AS INTEGER
    i = j = k = 0
    ON ERROR RESUME NEXT
    szResult = ""
       
        DO WHILE i < LEN(szOriginal)
            i = i + 1
            szTemp = Trim(Mid(szOriginal, (i), 1))
            IF szTemp = Trim(oldcharacter) AND i <= LEN(szOriginal) THEN
                k = k + 1
                Mid(szOriginal, i, 1) = newcharacter
                j = i + 1
            END IF
       
        LOOP

    ReplaceEachInstanceOfCharacter = szOriginal

END FUNCTION

FUNCTION ScrambleString(szRaw AS STRING, szKey AS STRING) AS STRING
   DIM nDigitSum AS INTEGER
   DIM i AS INTEGER
   DIM szCooked AS STRING
   DIM nRawLength AS INTEGER
   DIM szMask AS STRING
   DIM nDigit AS INTEGER
   DIM nDigitMask AS INTEGER

   nDigitSum = 0
   FOR i = 1 TO LEN(szKey)
      nDigitSum = nDigitSum + ASC(MID$(szKey, i, 1))
   NEXT
   nDigitSum = nDigitSum MOD 128

   szCooked = ""
   
   nRawLength = LEN(szRaw)

   szMask = szKey
   DO WHILE LEN(szMask) < nRawLength
      szMask = szMask + szKey
   LOOP
   
   FOR i = 1 TO LEN(szRaw)
      ' To scramble = digit + digitsum of key XOR character of key
      nDigit = ASC(MID$(szRaw, i, 1)) + nDigitSum
      nDigitMask = ASC(MID$(szMask, i, 1))
      nDigit = nDigit XOR nDigitMask
      szCooked = szCooked + CHR$(nDigit)
   NEXT

   'MsgBox "Raw = '" + szRaw + "'  Cooked='" + szCooked + "'"

   ScrambleString = szCooked
END FUNCTION

FUNCTION UnscrambleString(szCooked AS STRING, szKey AS STRING) AS STRING
   DIM nDigitSum AS INTEGER
   DIM i AS INTEGER
   DIM szRaw AS STRING
   DIM nCookedLength AS INTEGER
   DIM szMask AS STRING
   DIM nDigit AS INTEGER
   DIM nDigitMask AS INTEGER

   szRaw = ""

   nDigitSum = 0
   FOR i = 1 TO LEN(szKey)
      nDigitSum = nDigitSum + ASC(MID$(szKey, i, 1))
   NEXT
   nDigitSum = nDigitSum MOD 128

   nCookedLength = LEN(szCooked)

   szMask = szKey
   DO WHILE LEN(szMask) < nCookedLength
      szMask = szMask + szKey
   LOOP
   
   FOR i = 1 TO LEN(szCooked)
      ' To unscramble = digitsum of key XOR character of key - digit
      nDigit = ASC(MID$(szCooked, i, 1))
      nDigitMask = ASC(MID$(szMask, i, 1))
      nDigit = nDigit XOR nDigitMask
      nDigit = nDigit - nDigitSum
      szRaw = szRaw + CHR$(nDigit)
   NEXT

   'MsgBox "Cooked = '" + szCooked + "'  Raw='" + szRaw + "'"

   UnscrambleString = szRaw

END FUNCTION


LockScreen 1.0
This small code enables you to lock the screen.Here all the keys like Ctrl+Alt+Del will be disabled. Download MY rRemote Sys control. and eplore more knowledge
VISOCO dbExpress driver for Sybase ASA (Linux version) 2.0
VISOCO dbExpress driver for Sybase ASA is based on the Embedded SQL database interface, provide direct access to Sybase ASA and allows avoiding Borland Database Engine (BDE), ODBC, ADO, SQL Links and...
Programming Arcade Games
Is a tutorial on programming object oriented arcade games in Turbo C.
Download LockScreen 1.0 This small code enables you to lock the screen.Here all the  keys like Ctrl+Alt+Del will be disabled. Download MY rRemote  Sys control. and eplore more knowledge Download VISOCO dbExpress driver for Sybase ASA (Linux version) 2.0 VISOCO dbExpress driver for Sybase ASA is based on the Embedded SQL database interface, provide direct access to Sybase ASA and allows avoiding Borland Database Engine (BDE), ODBC, ADO, SQL Links and... Download Programming Arcade Games Is a tutorial on programming object oriented arcade games in  Turbo C.







Sponsored links

Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Check Out IT Certification Preparation Materials
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
Localize software in three simple steps
Localize .Net, C/C++ & Delphi apps visually. HTML, HTML Help, XML & databases. Try Sisulizer now!
Delphi Localization Tool Sisulizer (WYSIWYG)
Create multilingual Delphi apps in three simple steps. Localize XML, HTML Help ... Try Sisulizer now
Web based bug tracking - AdminiTrack.com
AdminiTrack offers an effective web-based bug tracking system designed for professional software development teams.


Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.