By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,678 Members | 1,129 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,678 IT Pros & Developers. It's quick & easy.

How to only get char from string

P: 24
Hi i have problem with separating Character from string,

e.g:
dim S as string
dim k as string

S="23 * 12 UBV 100";

how to i get output k="UBV"

Its mean only char set if together then i want to put in other variable,

any idea how to I start this.... Thx very much
Mar 18 '08 #1
Share this Question
Share on Google+
4 Replies


QVeen72
Expert 100+
P: 1,445
Hi,

Try this if the String Length is fixed..:
k = Mid("23 * 12 UBV 100",9,3)

Regards
Veena
Mar 18 '08 #2

debasisdas
Expert 5K+
P: 8,127
Its mean only char set if together then i want to put in other variable,
If you want only characters then find out all the digits and replace them with space and finally remove space but not the intermediate spaces.
Mar 18 '08 #3

P: 24
Hi,

Try this if the String Length is fixed..:
k = Mid("23 * 12 UBV 100",9,3)

Regards
Veena
Hi Veena,

Your idea is ok, however, Value of S can be change. I mean I dont know the exactvalue of S, but I know it is including with digit and character, so i want to seperate only characters, Thx again
Mar 18 '08 #4

Expert 5K+
P: 8,434
The solution in post #3 should do the job. For example...

Expand|Select|Wrap|Line Numbers
  1. Public Function CharsOnly_V1(ByVal S As String) As String
  2.   Dim I As Long
  3.   For I = 0 To 9
  4.     S = Replace(S, Format$(I), "")
  5.   Next
  6.   CharsOnly_V1 = Trim$(S)
  7. End Function
  8.  
Demo...
Print charsonly_v1(" db dfgjlh 35jkl sekjh 54 4")
db dfgjlh jkl sekjh

Here's another alternative which has the advantage of allowing you more control over which characters are copied and which aren't.

Expand|Select|Wrap|Line Numbers
  1. Public Function CharsOnly_V2(ByVal S As String) As String
  2.   Dim I As Long, Char As String * 1
  3.   For I = 1 To Len(S)
  4.     Char = Mid$(S, I, 1)
  5.     Select Case Char
  6.       Case "0" To "9"
  7.         ' Don't touch.
  8.       Case "a" To "z"
  9.         CharsOnly_V2 = CharsOnly_V2 & Char
  10.       Case "A" To "Z"
  11.         CharsOnly_V2 = CharsOnly_V2 & Char
  12.       Case Else
  13.         ' Don't touch.
  14.     End Select
  15.   Next
  16. End Function
  17.  
Demo...

Print charsonly_v2(" db dfgjlh 35jkl sekjh 54 4")
dbdfgjlhjklsekjh
Mar 19 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.