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

Removing numbers from a string

P: 1
I want to remove the numbers and letters on the left on a string.

I have some strings which read as such:


ATT 2393747394
AT&T 2732372Tom
CAN Air38263
AA3333333

I tried to use a Left function with InStr within it. Left([Title],(InStr([Title],"#")-1)) The result of that function deleted the whole string. I was wondering whether there is a way to get what I seek.

I seek this result:

ATT
AT&T
CAN Air
AA

Thanks in advance.
Nov 18 '08 #1
Share this Question
Share on Google+
2 Replies


ADezii
Expert 5K+
P: 8,597
I whipped this up in a hurray, but it should do the trick with little or no modifications:
Expand|Select|Wrap|Line Numbers
  1. Public Function fRemoveCharsFromLeft(strString As String) As String
  2. Dim intLen As Integer
  3. Dim intCharCounter As Integer
  4. Dim strBuildString As String
  5.  
  6. intLen = Len(strString)
  7.  
  8. 'Extract all Characters from the Left of the String until the 1st Number
  9. For intCharCounter = 1 To intLen
  10.   If Not IsNumeric(Mid$(strString, intCharCounter, 1)) Then
  11.     strBuildString = strBuildString & Mid$(strString, intCharCounter, 1)
  12.   Else
  13.     fRemoveCharsFromLeft = Trim(strBuildString)
  14.       Exit Function
  15.   End If
  16. Next
  17.   fRemoveCharsFromLeft = Trim(strBuildString)
  18. End Function
Expand|Select|Wrap|Line Numbers
  1. ? fRemoveCharsFromLeft("ATT 2393747394")
  2. ATT
Expand|Select|Wrap|Line Numbers
  1. ? fRemoveCharsFromLeft("AT&T 2732372Tom")
  2. AT&T
Expand|Select|Wrap|Line Numbers
  1. ? fRemoveCharsFromLeft("CAN Air38263")
  2. CAN Air
Expand|Select|Wrap|Line Numbers
  1. ? fRemoveCharsFromLeft("AA3333333")
  2. AA
Expand|Select|Wrap|Line Numbers
  1. ? fRemoveCharsFromLeft("Look guys, not a single number!")
  2. Look guys, not a single number!
Expand|Select|Wrap|Line Numbers
  1. ? fRemoveCharsFromLeft("6This one number fouled up the works!")
  2. 'Returns an Empty String
Expand|Select|Wrap|Line Numbers
  1. ? fRemoveCharsFromLeft("She sells seashells 9 by the seashore")
  2. She sells seashells
Expand|Select|Wrap|Line Numbers
  1. ? fRemoveCharsFromLeft()
  2. 'Will definately generate an Error!
Nov 19 '08 #2

missinglinq
Expert 2.5K+
P: 3,532
Your duplicate posting of this problem, posted two hours prior to this thread, has been deleted! Please refrain from this prohibited behavior in the future.

From FAQs

Do Not Double Post Your Questions

Double posting is where you start a thread on a topic and then for some reason start another thread on exactly the same topic in the same forum. Please do not do this because

1. It makes it very hard for people to answer you especially if there are answers happening in all the threads you have started because they have to read 2 or more threads in order to see what has already been said.

2. It swamps the forum with your problem resulting in less attention for the other threads.

If you feel for some reason that you post has been overlooked (for instance it hasn't had any replies after 24 hours) please do not repost the question. Post a message to the thread you started, this will bump it back to the top of the thread list for the forum.

Thank you for your attention in this matter.

Linq ;0)>

Moderator
Nov 19 '08 #3

Post your reply

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