Solved

Trim a string - how?

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now