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
Solved

Trim a string - how?

Posted on 2000-03-17
4
127 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

861 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