Split String and Numbers

0 views
Skip to first unread message

Yogesh Jangam

unread,
Jul 19, 2005, 4:48:18 AM7/19/05
to program...@googlegroups.com
Often we require to sort data in our applications
NOrmally a string sort using SQL ORDER BY would suffice in such
situtaions

But in cases where we have string and numbers together

Ex.

UserLoginName

amit2568
yogesh456
neeraj12
subrimaniumnamboodripad2
yogesh1

is such case string sort wud not work because it wud sort like below
yogesh1
yogesh10
yogesh2
yogesh3
.
.
.

So when we were thinking for a efficient solution which wud sort as per
string and number.....we wud require a function which wud split string
and numeric part ....

So here it goes
'=================================================================
Private Sub SplitStringAndNum
''To Split a string and number combination
'' 'yogesh1423' ===> 'yogesh' and '1423'
Dim s As String, t As String
Dim n As Long
Dim p As Long
s = "yogesh123"
t = s
t = StrReverse(s)
n = StrReverse(CStr(Val(t)))
p = InStr(s, n)
If p > 1 Then
MsgBox Mid(s, 1, p - 1) & vbTab & Mid(s, p, Len(s))
End If
End Sub
'=================================================================
Cheers

Reply all
Reply to author
Forward
0 new messages