Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Trim a string - how?

Posted on 2000-03-17
4
Medium Priority
?
140 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 100 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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 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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

886 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