Solved

Trim a string - how?

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Exit a vb6 apps when a calling it apps closes 15 58
using web browser with BING 40 136
Problem to With line 4 76
Get the Y value of a line at X in a chart in VBA 28 28
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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

726 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