Solved

Trim a string - how?

Posted on 2000-03-17
4
130 Views
Last Modified: 2010-05-02
Hello experts!!

I have a simple problem;
I have a string like so; "username@somedomain.com" -
and I want to remove the last 15 characters, the "@somedomain.com"
.
How can I do so??

Thank you!

/Jens*
0
Comment
Question by:Jens979
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 9

Expert Comment

by:Ruchi
ID: 2628757
try something like this.
Private Sub Form_Load()
Dim a As String

a = "username@somedomain.com"
Text1.Text = Left$(a, 8)
End Sub
0
 
LVL 9

Accepted Solution

by:
kprestage earned 25 total points
ID: 2628800
I assume that you dont always know that it will be 15 characters.  In that case, you would need to loop through the string to find the @ symbol.

dim symbolLocation as integer
dim TrimmedString as string

for i=1 to len(stringname)
  if mid(stringname,i,1) = "@" then
    symbolLocation = i
  end if
next i

'this sets TrimmedString = to the original minus the unwanted characters
TrimmedString = left(stringname, symbolLocation - 1)

Hope this helps



0
 

Author Comment

by:Jens979
ID: 2628847
Very nice!!
:)
Thank you!

/Jens*
0
 

Expert Comment

by:rjjr
ID: 2629207
Try using this.  You might get better performance

Public Function TrimEmail(strEmail As String) As String
Dim llLocation As Long

llLocation = InStr(strEmail, "@") - 1
If llLocation > 0 Then
  TrimEmail = Left(strEmail, InStr(strEmail, "@") - 1)
Else
  TrimEmail = strEmail
End If
End Function
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question