473,732 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

whats the best way to do this?

I have to create 2 strings and then parse one string out to save the data
into the database.

My first string looks like this:

Jo************* **@yahoo.com,Gr ***********@aol .com,Ke******** ****@gmail.com,

I then need to parse out that string to seperate them by the commas so I see
this
Jo************* **@yahoo.com
Gr***********@a ol.com
Ke************@ gmail.com
I then need to parse out that string so I get
John
Greg
Kelly

Smith
Henry
Smith

so I can save each value to the database, what is the best way to do this?
The stored procedure I'm calling is already parsing strings by the comma, so
would it be easier to just parse out the large string in code and pass the
smaller string with the pipe (|) and make a change to the proc to parse the
values by the (|) or should I do all of this in my C# code? If the C# way,
how would that be done? I'm able to get this string format
(Jo************ ***@yahoo.com) but when I try to parse it out, I' get errors
(Index was outside the bounds of the array)

Jul 12 '07 #1
19 2137
Hi Steve,

SJ************* ***@yahoo.com,G r***********@ao l.com,Kelly|Smi th|ks@gmai

The <string>.Split( <separator>) method can be helpful.
http://msdn2.microsoft.com/en-us/lib...ing.split.aspx

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com
Jul 12 '07 #2
I am currently doing that but when I split the first string by the comma(,)
its fine, its the second string Jo************* **@yahoo.com thats giving me
a fit.

when i do this:

String[] names= ViewState["custnames"].ToString().Spl it('|');
foreach (String n in names)
{
String[] u = n.ToString().Sp lit('|');
Response.Write( u[0]);
Response.Write( u[1]);
}

I'm getting this error:
Index was outside the bounds of the array, but if I do this
String[] names= ViewState["custnames"].ToString().Spl it('|');
foreach (String n in names)
{
String[] u = n.ToString().Sp lit('|');
Response.Write( u[0]);
}

I can see the first name in the string with no problem. So am I missing
something or doing something wrong in the sytnax?


"Alex Meleta" <am*****@gmail. comwrote in message
news:15******** *************** ***@msnews.micr osoft.com...
Hi Steve,

SJo************ ***@yahoo.com,G r***********@ao l.com,Kelly|Smi th|ks@gmai

The <string>.Split( <separator>) method can be helpful.
http://msdn2.microsoft.com/en-us/lib...ing.split.aspx

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com


Jul 12 '07 #3
"Steve" <St***@communit y.nospam.comwro te in message
news:O7******** ******@TK2MSFTN GP02.phx.gbl...
so I can save each value to the database, what is the best way to do this?
strRaw =
"Jo************ ***@yahoo.com,G r***********@ao l.com,Ke******* *****@gmail.com ,";

foreach (string strRecord in strRaw.Split(', '))
{
string[] astrElements = strRecord.Split ('|');

strFirstName = astrElements[0];
strLastName = astrElements[1];
strEmailAddress = astrElements[2];
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 12 '07 #4
Mark,
I've tried that, I've tried everything I can think of and it only shows
[0] and anything beyond that give me the out of bounds error message.
"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:e8******** ******@TK2MSFTN GP04.phx.gbl...
"Steve" <St***@communit y.nospam.comwro te in message
news:O7******** ******@TK2MSFTN GP02.phx.gbl...
>so I can save each value to the database, what is the best way to do
this?

strRaw =
"Jo************ ***@yahoo.com,G r***********@ao l.com,Ke******* *****@gmail.com ,";

foreach (string strRecord in strRaw.Split(', '))
{
string[] astrElements = strRecord.Split ('|');

strFirstName = astrElements[0];
strLastName = astrElements[1];
strEmailAddress = astrElements[2];
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 12 '07 #5
"Steve" <St***@communit y.nospam.comwro te in message
news:O5******** ******@TK2MSFTN GP05.phx.gbl...
I've tried that, I've tried everything I can think of and it only shows
[0] and anything beyond that give me the out of bounds error message.
Not sure what's happening, then - I've just tried it, and it works fine for
me.

Can you post your whole code...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 12 '07 #6
Hi Steve,

Probably the exception occurs in that piece of code:
SResponse.Write (u[1]);

You should check the boundaries.
Anyway, you can try to analyse that input string is correct, for doing this
change your code to something like code below:

foreach (String n in names)
{
foreach(String justForTest in n.ToString().Sp lit('|'))
{ Response.WriteL ine(justForTest ); }
Response.WriteL ine("-");
}

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com

SI am currently doing that but when I split the first string by the
Scomma(,) its fine, its the second string Jo************* **@yahoo.com
Sthats giving me a fit.
S>
Swhen i do this:
S>
SString[] names= ViewState["custnames"].ToString().Spl it('|');
Sforeach (String n in names)
S{
SString[] u = n.ToString().Sp lit('|');
SResponse.Write (u[0]);
SResponse.Write (u[1]);
S}
SI'm getting this error:
SIndex was outside the bounds of the array, but if I do this
SString[] names= ViewState["custnames"].ToString().Spl it('|');
Sforeach (String n in names)
S{
SString[] u = n.ToString().Sp lit('|');
SResponse.Write (u[0]);
S}
SI can see the first name in the string with no problem. So am I
Smissing something or doing something wrong in the sytnax?
S>
S"Alex Meleta" <am*****@gmail. comwrote in message
Snews:15******* *************** ****@msnews.mic rosoft.com...
S>
>Hi Steve,

S>
Jo************ ***@yahoo.com,G r***********@ao l.com,Kelly|Smi th|ks@gmai

The <string>.Split( <separator>) method can be helpful.
http://msdn2.microsoft.com/en-us/lib...ing.split.aspx

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com

Jul 12 '07 #7
sure:

code:
main string:
Jo************* **@yahoo.com,Gr ***********@aol .com,Ke******** ****@gmail.com,

String[] users= ViewState["Stuff"].ToString().Spl it(',');

which returns this:
Jo************* **@yahoo.com,

then I loop through that string;
foreach (string s in users)
{
string[] s= strRecord.Split ('|');

strFirstName = s[0];
strLastName = s[1];
strEmail = s[2];
}
Response.Write( strFirstName + " " + strLastName + " " +
strEmail);

and I get this error:
Index was outside the bounds of the array.
strLastName = astrElements[1];

"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:eb******** ******@TK2MSFTN GP03.phx.gbl...
"Steve" <St***@communit y.nospam.comwro te in message
news:O5******** ******@TK2MSFTN GP05.phx.gbl...
>I've tried that, I've tried everything I can think of and it only shows
[0] and anything beyond that give me the out of bounds error message.

Not sure what's happening, then - I've just tried it, and it works fine
for me.

Can you post your whole code...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 12 '07 #8
I've done that and I can see the string that is being passed

Jo************* **@yahoo.com,Gr ***********@aol .com,Ke******** ****@gmail.com,

I can see that just fine, hell i can even parse it out by the commas, its
splitting this string:
Jo************* **@yahoo.com

thats joking on me

"Alex Meleta" <am*****@gmail. comwrote in message
news:15******** *************** ***@msnews.micr osoft.com...
Hi Steve,

Probably the exception occurs in that piece of code:
SResponse.Write (u[1]);

You should check the boundaries.
Anyway, you can try to analyse that input string is correct, for doing
this change your code to something like code below:

foreach (String n in names)
{
foreach(String justForTest in n.ToString().Sp lit('|'))
{ Response.WriteL ine(justForTest ); }
Response.WriteL ine("-");
}

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com

SI am currently doing that but when I split the first string by the
Scomma(,) its fine, its the second string Jo************* **@yahoo.com
Sthats giving me a fit.
SSwhen i do this:
SSString[] names= ViewState["custnames"].ToString().Spl it('|');
Sforeach (String n in names)
S{
SString[] u = n.ToString().Sp lit('|');
SResponse.Write (u[0]);
SResponse.Write (u[1]);
S}
SI'm getting this error:
SIndex was outside the bounds of the array, but if I do this
SString[] names= ViewState["custnames"].ToString().Spl it('|');
Sforeach (String n in names)
S{
SString[] u = n.ToString().Sp lit('|');
SResponse.Write (u[0]);
S}
SI can see the first name in the string with no problem. So am I
Smissing something or doing something wrong in the sytnax?
SS"Alex Meleta" <am*****@gmail. comwrote in message
Snews:15******* *************** ****@msnews.mic rosoft.com...
S>
>>Hi Steve,

S>
Jo*********** ****@yahoo.com, Gr***********@a ol.com,Kelly|Sm ith|ks@gmai

The <string>.Split( <separator>) method can be helpful.
http://msdn2.microsoft.com/en-us/lib...ing.split.aspx

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com


Jul 12 '07 #9
"Steve" <St***@communit y.nospam.comwro te in message
news:ep******** ******@TK2MSFTN GP06.phx.gbl...
sure:

code:
<snip>

Hmm - can't see anything obviously wrong with that...

I'm clutching at straws now, but could you tell me what s.Length returns?
I'm wondering if there's some sort of CultureInfo conflict here which has
caused the Split method to fail to interpret the pipe symbol correctly... If
s.Length returns 1 instead of 3, I think that might be the reason...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 12 '07 #10

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

Similar topics

1
1302
by: Eva | last post by:
Hi all, I just wanted some advise on what control is best to use in my situaton. What i am trying to achieve is to allow the user to enter 1 or more room names into a control of some sort so that they can be stored in a Database. The control should have the ability to adjust its size according to the number of room names entered. The room names in the control should also be easily read into the database. The entered data should have...
3
5363
by: Kevin Steffer | last post by:
Hi group I have a webform which I want to make an ftp connection for a filetransfer from. The thing is when I use the WebRequest class it says "The URI prefix is not recognized" and my URI is ftp://localhost/ Then I discovered that the WebRequest class has a RegisterPrefix method which takes a string as prefix and it needs a System.Net.IWebRequestCreate but how is such one made ?
2
1576
by: SOR | last post by:
I'm writing a guestbook and given the number of entrys the guestbook might have can vary quite a lot - the nav links to view the guestbook entrys need to generated live at the time to suit . Whats a good method to get the effect .
5
2484
by: Panama Red | last post by:
I would like to learn to program in c++ on Linux and AIX systems...mainly socket and fifo type stuff. Can someone recommend a book for someone with experience only with Perl, shell, and Pick/Basic ? Thanks
4
2004
by: David Lozzi | last post by:
OK simple question. Whats the default value for an string() array? sub LoadStuff(byval one as integer, byval two as string, optional byval three() as string = ??) Its driving me nuts! Thanks! --
4
1399
by: markrush | last post by:
if i have 2 datasources with different table names and column headers that i want to merge i.e. "ptitle" and "name" whats the best way of doing this? are there any standard routines or should i use something intermediary like xml? mark
16
1214
by: Brian Henry | last post by:
Is there a listing out there anywhere that lists what is new in .NET 2.0 mainly in VB? I've seen simple lists like oh we have all these new controls, but I want a class list and such also. thanks!
2
1246
by: moondaddy | last post by:
I'm using WPF and c#. Whats the best way for a child class to know about it's parent class? For examle class ParentClass : CollectionBase { // code... class ChildClass { // code...
4
3082
by: LoneHunter01 | last post by:
Basically, I just need a general direction on where to go for this. Yes, this is for a school project, though it's strictly an optional one (and I have tried many solutions, one in-depth). We've only covered a few types of data struct (vectors, heaps, stacks, queues, deques, lists, linked lists, priority queues, trees, etc.). I need to be able to read in a file and keep track of the number of times a word appears and then print out based...
7
2274
by: Paulo | last post by:
Hi, what is diference between: File -New Web Site and File -New Project -VB/C# -Web Application ?????? VS 2005
0
8774
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,...
0
9307
jinu1996
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...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
tracyyun
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...
0
4550
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...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
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.