Split Function

  • Thread starter Thread starter sck10
  • Start date Start date
S

sck10

Hello,

I have a list of email addresses that I need to send email to from the
website. I am trying to use the "Split" function to get all the To's and
then use the uBound function for the For-Loop limit:

I am trying to convert the following from vb to c#:

Dim SplitCatcher As Object
SplitCatcher = Split(To, ",")

Dim i As Integer
For i = 0 To UBound(SplitCatcher)
If Len(SplitCatcher(i)) > 0 Then objMM.To.Add(SplitCatcher(i))
Next

to

string[] SplitCatcher = Split(To, ",");
for (int i = 0; uBound(SplitCatcher); i++)
{
if (SplitCatcher.Length > 0) MM.To.Add(SplitCatcher);
}



Mail Code
====================
public void SendWebMail(string From, string To, string Subject, string Body,
string Client)
{
//Build Email List
MailMessage MM = new MailMessage();
MailAddress AddrFrom = new MailAddress(From);

// build recipient list
//MailAddress AddrTo = new MailAddress(To);
string[] SplitCatcher = Split(To, ",");
for (int i = 0; uBound(SplitCatcher); i++)
{
if (SplitCatcher.Length > 0) MM.To.Add(SplitCatcher);
}

MM.Subject = Subject;
MM.Body = Body;
SmtpClient scMail = new SmtpClient(Client);
scMail.Send(MM);

} //End void SendMail
 
I take it you have another closing curly brace at the end of your code
as there appears to be one missing from here.

Also, what exactly is your error?
 
Thanks,
For the Split function, I am getting the error: The name 'Split' does not
exist in the current context.

Thanks for your help with this.

sck10


Peter Bromberg said:
No "ubound" in C#!

for (int i = 0; i<SplitCatcher.Length; i++)

Cheers,
Peter


--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




sck10 said:
Hello,

I have a list of email addresses that I need to send email to from the
website. I am trying to use the "Split" function to get all the To's and
then use the uBound function for the For-Loop limit:

I am trying to convert the following from vb to c#:

Dim SplitCatcher As Object
SplitCatcher = Split(To, ",")

Dim i As Integer
For i = 0 To UBound(SplitCatcher)
If Len(SplitCatcher(i)) > 0 Then objMM.To.Add(SplitCatcher(i))
Next

to

string[] SplitCatcher = Split(To, ",");
for (int i = 0; uBound(SplitCatcher); i++)
{
if (SplitCatcher.Length > 0) MM.To.Add(SplitCatcher);
}



Mail Code
====================
public void SendWebMail(string From, string To, string Subject, string
Body,
string Client)
{
//Build Email List
MailMessage MM = new MailMessage();
MailAddress AddrFrom = new MailAddress(From);

// build recipient list
//MailAddress AddrTo = new MailAddress(To);
string[] SplitCatcher = Split(To, ",");
for (int i = 0; uBound(SplitCatcher); i++)
{
if (SplitCatcher.Length > 0) MM.To.Add(SplitCatcher);
}

MM.Subject = Subject;
MM.Body = Body;
SmtpClient scMail = new SmtpClient(Client);
scMail.Send(MM);

} //End void SendMail
 
This should work.

string to = "(e-mail address removed),[email protected]";
string[] SplitCatcher = to.split(',');

for (int i = 0; i<SplitCatcher.Length; i++)
{
if (SplitCatcher.Length > 0) MM.To.Add(SplitCatcher);
}
Thanks,
For the Split function, I am getting the error: The name 'Split' does not
exist in the current context.

Thanks for your help with this.

sck10


Peter Bromberg said:
No "ubound" in C#!

for (int i = 0; i<SplitCatcher.Length; i++)

Cheers,
Peter


--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




sck10 said:
Hello,

I have a list of email addresses that I need to send email to from the
website. I am trying to use the "Split" function to get all the To's and
then use the uBound function for the For-Loop limit:

I am trying to convert the following from vb to c#:

Dim SplitCatcher As Object
SplitCatcher = Split(To, ",")

Dim i As Integer
For i = 0 To UBound(SplitCatcher)
If Len(SplitCatcher(i)) > 0 Then objMM.To.Add(SplitCatcher(i))
Next

to

string[] SplitCatcher = Split(To, ",");
for (int i = 0; uBound(SplitCatcher); i++)
{
if (SplitCatcher.Length > 0) MM.To.Add(SplitCatcher);
}



Mail Code
====================
public void SendWebMail(string From, string To, string Subject, string
Body,
string Client)
{
//Build Email List
MailMessage MM = new MailMessage();
MailAddress AddrFrom = new MailAddress(From);

// build recipient list
//MailAddress AddrTo = new MailAddress(To);
string[] SplitCatcher = Split(To, ",");
for (int i = 0; uBound(SplitCatcher); i++)
{
if (SplitCatcher.Length > 0) MM.To.Add(SplitCatcher);
}

MM.Subject = Subject;
MM.Body = Body;
SmtpClient scMail = new SmtpClient(Client);
scMail.Send(MM);

} //End void SendMail
 
Thanks Gozirra,

Works perfect...


Gozirra said:
This should work.

string to = "(e-mail address removed),[email protected]";
string[] SplitCatcher = to.split(',');

for (int i = 0; i<SplitCatcher.Length; i++)
{
if (SplitCatcher.Length > 0) MM.To.Add(SplitCatcher);
}
Thanks,
For the Split function, I am getting the error: The name 'Split' does not
exist in the current context.

Thanks for your help with this.

sck10


message
No "ubound" in C#!

for (int i = 0; i<SplitCatcher.Length; i++)

Cheers,
Peter


--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




:

Hello,

I have a list of email addresses that I need to send email to from the
website. I am trying to use the "Split" function to get all the To's
and
then use the uBound function for the For-Loop limit:

I am trying to convert the following from vb to c#:

Dim SplitCatcher As Object
SplitCatcher = Split(To, ",")

Dim i As Integer
For i = 0 To UBound(SplitCatcher)
If Len(SplitCatcher(i)) > 0 Then objMM.To.Add(SplitCatcher(i))
Next

to

string[] SplitCatcher = Split(To, ",");
for (int i = 0; uBound(SplitCatcher); i++)
{
if (SplitCatcher.Length > 0) MM.To.Add(SplitCatcher);
}



Mail Code
====================
public void SendWebMail(string From, string To, string Subject, string
Body,
string Client)
{
//Build Email List
MailMessage MM = new MailMessage();
MailAddress AddrFrom = new MailAddress(From);

// build recipient list
//MailAddress AddrTo = new MailAddress(To);
string[] SplitCatcher = Split(To, ",");
for (int i = 0; uBound(SplitCatcher); i++)
{
if (SplitCatcher.Length > 0) MM.To.Add(SplitCatcher);
}

MM.Subject = Subject;
MM.Body = Body;
SmtpClient scMail = new SmtpClient(Client);
scMail.Send(MM);

} //End void SendMail

 
Back
Top