-
Sep 23rd, 2013, 09:20 PM
#1
Thread Starter
Lively Member
[RESOLVED] How to capture the first letter in a not-repeating string ?
Hi
I want to create a function for capturing the first letter in a not-repeating string
For example if have this :
MyString = "aabbccddMffrryx"
So the first letter will be retuned as M
So i'm looking for the best and the easy way to do it in vbscript.
So i ask you how can i do this function
Thank you !
-
Sep 23rd, 2013, 11:17 PM
#2
Re: How to capture the first letter in a not-repeating string ?
Try this one
Code:
Private Function GetFirstSingleLetter(ByVal strText As String) As String
Dim j As Long
Dim r As String
Dim c As String
For j = 1 To Len(strText)
c = Mid$(strText, j, 1)
If InStr(j + 1, strText, c, vbTextCompare) = 0 And c <> vbTab Then
r = c
Exit For
Else
' Replace repeated letter with vbTab in order to not find it again.
strText = Replace(strText, c, vbTab, , , vbTextCompare)
End If
Next
GetFirstSingleLetter = r
End Function
-
Sep 23rd, 2013, 11:44 PM
#3
Re: How to capture the first letter in a not-repeating string ?
Yet another way:
Code:
Private Function FindFirstNonRepeatingChar(ByRef Text)
Dim Pos, Length
Pos = 1
Length = Len(Text)
Do While Mid(Text, Pos, 1) = Mid(Text, Pos + 1, 1) And Pos < Length
Do: Pos = Pos + 1
Loop While Mid(Text, Pos, 1) = Mid(Text, Pos + 1, 1) And Pos < Length
Pos = Pos + 1
Loop
FindFirstNonRepeatingChar = Mid(Text, Pos, 1)
End Function
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|