Help with String manipulations 
Author Message
 Help with String manipulations

How do i retrieve just characters out of a string variable on at a time?


Sat, 06 Jan 2001 03:00:00 GMT  
 Help with String manipulations
Use "Mid" function and a loop.
This is not a good way to do it, but it works.

Dim StringVariable as String
Dim aChar as String

For I = 1 to Len(StringVariable)
   aChar = Mid$(StringVariable,I,1)
Next I


Quote:
> How do i retrieve just characters out of a string variable on at a time?



Sat, 06 Jan 2001 03:00:00 GMT  
 Help with String manipulations
I also have to manipulate character strings and I have found the following
to be usefull.

'***************************************************************************
***************
'Deletes all occurences of the character you pass in p_DelChar in p_TgtStr
'***************************************************************************
***************
Function DeleteChar(p_TgtStr As String, p_DelChar As String)
  Dim Result As String, Pos As Integer

  Result = p_TgtStr
  Pos = InStr(Result, p_DelChar)
  While Pos > 0
    Result = Left$(Result, Pos - 1) + Right$(Result, Len(Result) - Pos)
    Pos = InStr(Result, p_DelChar)
  Wend
  DeleteChar = Result
End Function

'***************************************************************************
*
'Deletes all characters not between 0 and 9
'***************************************************************************
*
Function DIGITSONLY(p_TgtStr As Variant) As String
  Dim p_Result As String, p_TgtLen As Integer, i As Integer, p_ChrVal As
Integer, p_ChrStr As String

  If IsNull(p_TgtStr) Then
    p_Result = ""
  Else
    p_TgtLen = Len(p_TgtStr)
    For i = 1 To p_TgtLen
      p_ChrStr = Mid$(p_TgtStr, i, 1)
      p_ChrVal = Asc(p_ChrStr)
      If ((p_ChrVal > 47) And (p_ChrVal < 58)) Then
        p_Result = p_Result + p_ChrStr
      End If
    Next i
  End If
  DIGITSONLY = p_Result
End Function

Public Sub ERROR_HIT()
    g_ErrorHit = True
    BDErrLog g_ErrorJob, g_ErrorDesc
    g_ErrorMsg = "Error during " & g_Option & " Build. " & g_ErrorDesc
    MsgBox g_ErrorMsg, gc_MB_ICONSTOP, ""
    Exit Sub

End Sub

Example of calls:

strip_string = DeleteChar(mid$(input, 1, 15), "-")
strip_string = DIGITSONLY(mid$(input, 1, 15))


Quote:
>How do i retrieve just characters out of a string variable on at a time?



Sun, 07 Jan 2001 03:00:00 GMT  
 Help with String manipulations
Well, one way is to do the following:

for index = 1 to len(String)
   c = mid$(String, 1, 1)
                 :
                 :
loop


Quote:
>How do i retrieve just characters out of a string variable on at a time?



Sun, 07 Jan 2001 03:00:00 GMT  
 Help with String manipulations

Quote:
>How do i retrieve just characters out of a string variable on at a time?

If you want to retrieve characters from the string one by one try
this:

For iCount = 1 To Len(YourString)
        strChar = Mid(YourString, iCount, 1)
        MsgBox strChar
Next



Tue, 09 Jan 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Need help with string manipulation...please!

2. Help on string manipulation

3. string manipulation, string routines, etc.

4. Please Help, string manipulation

5. Beginner String manipulation Help!

6. GPS NEMA string manipulation with VB5 help

7. GPS NEMA string manipulation with VB5 help

8. Student help - VB4 Proff String Manipulations - urgent

9. Help with VERY simple VB string manipulation

10. String manipulation help

11. Help for a Newbie: CSV data to be used in string manipulation

12. String manipulation help

 

 
Powered by phpBB® Forum Software