473,836 Members | 1,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help on vb.net strString.Subst ring( )

Could someone please help a newbee vb programmer with a question that
is driving me crazy. I am trying to understand a line of code that is
supposed to return the domain portion of a valid email address. The
following code works!

*************** *************** *************** *************** ******

strEmail = "j...@mydomain. com"

String2 = strEmail.Substr ing(strEmail.In dexOf("@") + 1, _
strEmail.IndexO f(".", strEmail.IndexO f("@") + 1) _
- strEmail.IndexO f("@") - 1)

*************** *************** *************** *************** ******

String2 will contain the string "mydomain" . I understand the IndexOf(
) method
will return a zero based index of the char your searching for and that
the method
string.Substrin g( ) returns a substring of a string using start and
size arguments,
ie: Substring( start, size) but if you look at the email above the
start position would be the
index of 5 or the 'm' in mydomain. the num chars would be 13 - 3 = 10
chars. So if you
start at the 5th char and return 10 char's I would think that you would
return the string
"mydomain.c ". Now to really get things confusing I did a little test
in the following code.

I broke up the different index search's only I took the index of the
period + 1 and subtracted
the position of the '@' sign + 1 which made more sense to me and I got
8 char's, then I used that value in the substring( ) procedure and I
get the correct answer. My confusion is how can both way's work?

Obviously I am really confused on this, if anyone could help with the
explanation I would really appreciate it.



*************** *************** *************** *************** **

Dim strEmail As String
Dim var1 As Integer
Dim var2 As Integer
Dim var3 As Integer
Dim String1 As String
Dim String2 As String

strEmail = "j...@mydomain. com"

var1 = strEmail.IndexO f("@") + 1
var2 = strEmail.IndexO f(".", strEmail.IndexO f("@") + 1)
var3 = var2 - var1

String1 = strEmail.Substr ing(strEmail.In dexOf("@") + 1, var3)

String2 = strEmail.Substr ing(strEmail.In dexOf("@") + 1, _
strEmail.IndexO f(".", strEmail.IndexO f("@") + 1) _
- strEmail.IndexO f("@") - 1)

Both String1 and String2 will = "mydomain"?

Nov 24 '05 #1
2 6419
the num chars would be 13 - 3 = 10 chars.

Where did you get 3 from? I get 13 - 4 - 1 = 8.

Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 24 '05 #2

Thanks for the response, as soon as you typed the simple line, 12
- 4 - 1 = 8 I could see what I was missing. In the last IndexOf( ) line
"strEmail.Index Of("@") - 1)" I took that line as "take the index of the
( @ sign minus 1) ie: in j...@mydomain.c om that would be 4-1 = 3 ) and
subtract from the index of the period" What I missed was that it's
"Subtract the index of the @ sign from the index of the period, and
then subtract one more". Man I can't believe I was that hung up on
something so simple. ugh!

Thanks a ton for you help :)


Nov 25 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Nikita A. Visnevski | last post by:
Hi everyone, I am rather new to Java beans. Just picked up a book last night and started reading about them. I am building an application that allows a user to define objects with dynamic properties. Something similar to a java hash table. One can add new properties at runtime and remove them as well. I have a really fancy third party property inspector available to me that I would very much like to reuse. This inspector uses...
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use SUBSTRING(ProductName, 1, CHARINDEX('(', ProductName)-2). I can get this result, but I had to use several views (totally inefficient). I think this can be done in one efficient/fast query, but I can't think of one. In the case that one query is not...
by: m.k.ball | last post by:
Thanks Rich - that's great. Before I found this group, I thought I had a reasonable understanding of SQL (well, MySQL's implementation of it, at least) but the truth is there are great chunks that I have no knowledge of. I've read three or four books about MySQL and PHP all of which gave (in retrospect) very basic examples of the use of SQL, and focussed on features such as MySQL's date and time handling functions that are well covered in...
by: manmit.walia | last post by:
Hello All and Thank You for your time, I am stuck on this exception handleing error. The problem is that when I run my application the application works perfect but sometimes, I get this error. I do not know where it is causing it but my guess would be something with the function below. Any help would be greatfull, as this would be a learning experience for me. For this example: swTitle.Text = "AutoCAD 2004" After the user selects the...
by: ash | last post by:
hi friends, i have some questions whch is in my last year question papers.i need some help to get logic of these questions. 1) write a C function, that takes two strings as arguments and returns a pointer to the first occurrence of 1st string in 2nd string or NULL if it is not present. -- i tried to solve it but it seems that i am not understanding this question at all.i am taking this question as:
by: sommarlov | last post by:
Hi everyone >From one of our systems an xml file is produced. I need to validate this file before we send it to an external system for a very lenghty process. I cannot change the xml file layout. The solution i got today is very slow, and i need help to find another solution. Here is the xml file. It consists of a list of position ids (ESTOXX50 INDEX_BM_E and FTSE INDEX_BM_E), and below that a list of tags for each position id. What i...
by: Learner | last post by:
Hello, I am trying to create few dynamic controls and once they are rendered I need to save the information that was entered into these dynamic fileds. For instance when I create 3 radio button dynamic controls I get the ID of this controls as rdb29OPT0 rdb30OPT1
by: donradii | last post by:
Hello all, I am new here and am new the world of javascripting. I am having a heck of a time trying to accomplish something that i conceptually know what i want to do but can not seem to get it into code correctly. What I am looking to do is this. I have a web page that uses 3 different formats of video. Right now to load each format I have 3 separate pages. Each format is loaded onto the page with an embed function.
by: Jonathan Wood | last post by:
I'm trying to duplicate an HTML sample I have using my ASP.NET pages. The sample contains the following within the <headtag: <script type="text/javascript" src="flashobject.js"></script> <script type="text/javascript"> // <!.indexOf('='); if( pos == -1 ) { continue; // Look for "name=value"
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.