Split Function

Discussion in 'ASP .Net' started by sck10, Aug 14, 2006.

  1. sck10

    sck10 Guest

    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
     
    sck10, Aug 14, 2006
    #1
    1. Advertising

  2. sck10

    Karl Guest

    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?


    sck10 wrote:
    > 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
     
    Karl, Aug 14, 2006
    #2
    1. Advertising

  3. 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" wrote:

    > 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
    >
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Aug 14, 2006
    #3
  4. sck10

    sck10 Guest

    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 [C# MVP]" <> wrote in message
    news:...
    > 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" wrote:
    >
    >> 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
    >>
    >>
    >>
     
    sck10, Aug 14, 2006
    #4
  5. sck10

    Gozirra Guest

    This should work.

    string to = ",";
    string[] SplitCatcher = to.split(',');

    for (int i = 0; i<SplitCatcher.Length; i++)
    {
    if (SplitCatcher.Length > 0) MM.To.Add(SplitCatcher);
    }

    sck10 wrote:
    > 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 [C# MVP]" <> wrote in message
    > news:...
    > > 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" wrote:
    > >
    > >> 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
    > >>
    > >>
    > >>
     
    Gozirra, Aug 14, 2006
    #5
  6. sck10

    sck10 Guest

    Thanks Gozirra,

    Works perfect...


    "Gozirra" <> wrote in message
    news:...
    > This should work.
    >
    > string to = ",";
    > string[] SplitCatcher = to.split(',');
    >
    > for (int i = 0; i<SplitCatcher.Length; i++)
    > {
    > if (SplitCatcher.Length > 0) MM.To.Add(SplitCatcher);
    > }
    >
    > sck10 wrote:
    >> 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 [C# MVP]" <> wrote in
    >> message
    >> news:...
    >> > 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" wrote:
    >> >
    >> >> 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
    >> >>
    >> >>
    >> >>

    >
     
    sck10, Aug 14, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    480
  2. Carlos Ribeiro
    Replies:
    11
    Views:
    720
    Alex Martelli
    Sep 17, 2004
  3. trans.  (T. Onoma)

    split on '' (and another for split -1)

    trans. (T. Onoma), Dec 27, 2004, in forum: Ruby
    Replies:
    10
    Views:
    227
    Florian Gross
    Dec 28, 2004
  4. Sam Kong
    Replies:
    5
    Views:
    261
    Rick DeNatale
    Aug 12, 2006
  5. Stanley Xu
    Replies:
    2
    Views:
    671
    Stanley Xu
    Mar 23, 2011
Loading...

Share This Page