Trouble Using System.Array.ForEach

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan Sokalski

    #1

    Trouble Using System.Array.ForEach

    I am trying to use the System.Array.Fo rEach method in VB.NET. The action
    that I want to perform on each of the Array values is:

    Private Function AddQuotes(ByVal value As String) As String
    Return String.Format(" '{0}'", value)
    End Function

    Basically, I just want to surround each value with single quotes. However, I
    am having trouble getting this to work using the System.Array.Fo rEach
    method. This may be partially because I am not very experienced with Actions
    or Delegates, so if somebody could tell me what I am doing wrong, I would
    appreciate it. Thanks. (NOTE: The Array that I want to modify the values of
    is not one that I have permission to modify (it is
    System.Globaliz ation.DateTimeF ormatInfo.Curre ntInfo.DayNames ()), so if
    anybody knows of a way to do this inline without declaring another Array,
    that would be nice as well)
    --
    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。



  • =?Utf-8?B?TW9kZWxCdWlsZGVy?=

    #2
    RE: Trouble Using System.Array.Fo rEach

    The Action type for the ForEach method requires a subroutine that takes no
    parameters. I've never tried this method, but it doesn't seem useful for
    your situation. How about starting with the following:


    For Each dayofweek As String In _
    System.Globaliz ation.DateTimeF ormatInfo.Curre ntInfo.DayNames

    Console.Out.Wri teLine(AddQuote s(dayofweek))
    Next


    "Nathan Sokalski" wrote:
    I am trying to use the System.Array.Fo rEach method in VB.NET. The action
    that I want to perform on each of the Array values is:
    >
    Private Function AddQuotes(ByVal value As String) As String
    Return String.Format(" '{0}'", value)
    End Function
    >
    Basically, I just want to surround each value with single quotes. However, I
    am having trouble getting this to work using the System.Array.Fo rEach
    method. This may be partially because I am not very experienced with Actions
    or Delegates, so if somebody could tell me what I am doing wrong, I would
    appreciate it. Thanks. (NOTE: The Array that I want to modify the values of
    is not one that I have permission to modify (it is
    System.Globaliz ation.DateTimeF ormatInfo.Curre ntInfo.DayNames ()), so if
    anybody knows of a way to do this inline without declaring another Array,
    that would be nice as well)
    --
    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。

    >
    >
    >

    Comment

    • Nathan Sokalski

      #3
      Re: Trouble Using System.Array.Fo rEach

      That would get me the quotes around each of the days, but I was hoping to do
      something like this:

      String.Join("," ,System.Globali zation.DateTime FormatInfo.Curr entInfo.DayName s())

      so that I could have the DayNames separated by commas. However, the code
      that I have above would not place each day inside quotes. Do I know of ways
      to create this comma-delimited String? Of course, but using a for loop would
      require me to either include an if statement determining when I am at the
      last value or manually remove the comma from the end of the String. I
      figured if I could just use the String.Join instead, I wouldn't have to deal
      with so many Strings and If statements. And, even though it may be just a
      thirst for knowledge, I would like to know how to use the ForEach method for
      future reference. Thanks.
      --
      Nathan Sokalski
      njsokalski@hotm ail.com
      有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。


      "ModelBuild er" <ModelBuilder@d iscussions.micr osoft.comwrote in message
      news:5E4EACCE-CF4D-4FA6-B2BB-51B8082841C8@mi crosoft.com...
      The Action type for the ForEach method requires a subroutine that takes no
      parameters. I've never tried this method, but it doesn't seem useful for
      your situation. How about starting with the following:
      >
      >
      For Each dayofweek As String In _
      System.Globaliz ation.DateTimeF ormatInfo.Curre ntInfo.DayNames
      >
      Console.Out.Wri teLine(AddQuote s(dayofweek))
      Next
      >
      >
      "Nathan Sokalski" wrote:
      >
      >I am trying to use the System.Array.Fo rEach method in VB.NET. The action
      >that I want to perform on each of the Array values is:
      >>
      >Private Function AddQuotes(ByVal value As String) As String
      > Return String.Format(" '{0}'", value)
      >End Function
      >>
      >Basically, I just want to surround each value with single quotes.
      >However, I
      >am having trouble getting this to work using the System.Array.Fo rEach
      >method. This may be partially because I am not very experienced with
      >Actions
      >or Delegates, so if somebody could tell me what I am doing wrong, I would
      >appreciate it. Thanks. (NOTE: The Array that I want to modify the values
      >of
      >is not one that I have permission to modify (it is
      >System.Globali zation.DateTime FormatInfo.Curr entInfo.DayName s()), so if
      >anybody knows of a way to do this inline without declaring another Array,
      >that would be nice as well)
      >--
      >Nathan Sokalski
      >njsokalski@hotm ail.com
      >http://www.nathansokalski.com/
      >>
      >>
      >>

      Comment

      • Stephany Young

        #4
        Re: Trouble Using System.Array.Fo rEach

        "'" & String.Join("', '", DateTimeFormatI nfo.CurrentInfo .DayNames) & "'"

        or

        String.Format(" '{0}'", String.Join("', '",
        DateTimeFormatI nfo.CurrentInfo .DayNames))


        "Nathan Sokalski" <njsokalski@hot mail.comwrote in message
        news:umVqfoZ7HH A.4880@TK2MSFTN GP03.phx.gbl...
        That would get me the quotes around each of the days, but I was hoping to
        do something like this:
        >
        String.Join("," ,System.Globali zation.DateTime FormatInfo.Curr entInfo.DayName s())
        >
        so that I could have the DayNames separated by commas. However, the code
        that I have above would not place each day inside quotes. Do I know of
        ways to create this comma-delimited String? Of course, but using a for
        loop would require me to either include an if statement determining when I
        am at the last value or manually remove the comma from the end of the
        String. I figured if I could just use the String.Join instead, I wouldn't
        have to deal with so many Strings and If statements. And, even though it
        may be just a thirst for knowledge, I would like to know how to use the
        ForEach method for future reference. Thanks.
        --
        Nathan Sokalski
        njsokalski@hotm ail.com
        有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。

        >
        "ModelBuild er" <ModelBuilder@d iscussions.micr osoft.comwrote in message
        news:5E4EACCE-CF4D-4FA6-B2BB-51B8082841C8@mi crosoft.com...
        >The Action type for the ForEach method requires a subroutine that takes
        >no
        >parameters. I've never tried this method, but it doesn't seem useful for
        >your situation. How about starting with the following:
        >>
        >>
        > For Each dayofweek As String In _
        > System.Globaliz ation.DateTimeF ormatInfo.Curre ntInfo.DayNames
        >>
        > Console.Out.Wri teLine(AddQuote s(dayofweek))
        > Next
        >>
        >>
        >"Nathan Sokalski" wrote:
        >>
        >>I am trying to use the System.Array.Fo rEach method in VB.NET. The action
        >>that I want to perform on each of the Array values is:
        >>>
        >>Private Function AddQuotes(ByVal value As String) As String
        >> Return String.Format(" '{0}'", value)
        >>End Function
        >>>
        >>Basically, I just want to surround each value with single quotes.
        >>However, I
        >>am having trouble getting this to work using the System.Array.Fo rEach
        >>method. This may be partially because I am not very experienced with
        >>Actions
        >>or Delegates, so if somebody could tell me what I am doing wrong, I
        >>would
        >>appreciate it. Thanks. (NOTE: The Array that I want to modify the values
        >>of
        >>is not one that I have permission to modify (it is
        >>System.Global ization.DateTim eFormatInfo.Cur rentInfo.DayNam es()), so if
        >>anybody knows of a way to do this inline without declaring another
        >>Array,
        >>that would be nice as well)
        >>--
        >>Nathan Sokalski
        >>njsokalski@hotm ail.com
        >>http://www.nathansokalski.com/
        >>>
        >>>
        >>>
        >
        >

        Comment

        • =?Utf-8?B?TW9kZWxCdWlsZGVy?=

          #5
          Re: Trouble Using System.Array.Fo rEach

          This will avoid the leading comma:


          dim n as integer = CurrentInfo.Day Names.Length - 1
          dim s as string = CurrentInfo.Day Names(0)

          for i = 1 to n
          s = string.Format(" {0}, {1}", s, CurrentInfo.Day Names(i))
          next


          "Nathan Sokalski" wrote:
          That would get me the quotes around each of the days, but I was hoping to do
          something like this:
          >
          String.Join("," ,System.Globali zation.DateTime FormatInfo.Curr entInfo.DayName s())
          >
          so that I could have the DayNames separated by commas. However, the code
          that I have above would not place each day inside quotes. Do I know of ways
          to create this comma-delimited String? Of course, but using a for loop would
          require me to either include an if statement determining when I am at the
          last value or manually remove the comma from the end of the String. I
          figured if I could just use the String.Join instead, I wouldn't have to deal
          with so many Strings and If statements. And, even though it may be just a
          thirst for knowledge, I would like to know how to use the ForEach method for
          future reference. Thanks.
          --
          Nathan Sokalski
          njsokalski@hotm ail.com
          有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。

          >
          "ModelBuild er" <ModelBuilder@d iscussions.micr osoft.comwrote in message
          news:5E4EACCE-CF4D-4FA6-B2BB-51B8082841C8@mi crosoft.com...
          The Action type for the ForEach method requires a subroutine that takes no
          parameters. I've never tried this method, but it doesn't seem useful for
          your situation. How about starting with the following:


          For Each dayofweek As String In _
          System.Globaliz ation.DateTimeF ormatInfo.Curre ntInfo.DayNames

          Console.Out.Wri teLine(AddQuote s(dayofweek))
          Next


          "Nathan Sokalski" wrote:
          I am trying to use the System.Array.Fo rEach method in VB.NET. The action
          that I want to perform on each of the Array values is:
          >
          Private Function AddQuotes(ByVal value As String) As String
          Return String.Format(" '{0}'", value)
          End Function
          >
          Basically, I just want to surround each value with single quotes.
          However, I
          am having trouble getting this to work using the System.Array.Fo rEach
          method. This may be partially because I am not very experienced with
          Actions
          or Delegates, so if somebody could tell me what I am doing wrong, I would
          appreciate it. Thanks. (NOTE: The Array that I want to modify the values
          of
          is not one that I have permission to modify (it is
          System.Globaliz ation.DateTimeF ormatInfo.Curre ntInfo.DayNames ()), so if
          anybody knows of a way to do this inline without declaring another Array,
          that would be nice as well)
          --
          Nathan Sokalski
          njsokalski@hotm ail.com
          有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。

          >
          >
          >
          >
          >
          >

          Comment

          • Nathan Sokalski

            #6
            Re: Trouble Using System.Array.Fo rEach

            I know how to do string manipulation, that is a very simple task. However,
            in several of my cases I want to not only add quotes to each element, but
            take the substring of it as well (for example, in some cases I want an array
            of only the first letter of each day). The techniques people have mentioned
            so far are great when I want the entire name, but when I need to do
            something like get just the first letter, or if I want it in all capitals,
            etc., I would require either a loop of some sort (which is what I am trying
            to avoid) or the ForEach method. I appreciate everyone's suggestions on how
            to use loops and string manipulation, but unfortunately (well, fortunately
            actually) I already know those techniques. So unless you are going to help
            me figure out how to use ForEach, save yourself the effort of showing me
            string manipulation and help someone else that is still learning loops and
            all the string manipulation techniques. But I still thank you for your time
            and effort.
            --
            Nathan Sokalski
            njsokalski@hotm ail.com
            有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。


            "ModelBuild er" <ModelBuilder@d iscussions.micr osoft.comwrote in message
            news:19073C71-3202-4285-BBEB-59A81BDCF386@mi crosoft.com...
            This will avoid the leading comma:
            >
            >
            dim n as integer = CurrentInfo.Day Names.Length - 1
            dim s as string = CurrentInfo.Day Names(0)
            >
            for i = 1 to n
            s = string.Format(" {0}, {1}", s, CurrentInfo.Day Names(i))
            next
            >
            >
            "Nathan Sokalski" wrote:
            >
            >That would get me the quotes around each of the days, but I was hoping to
            >do
            >something like this:
            >>
            >String.Join(", ",System.Global ization.DateTim eFormatInfo.Cur rentInfo.DayNam es())
            >>
            >so that I could have the DayNames separated by commas. However, the code
            >that I have above would not place each day inside quotes. Do I know of
            >ways
            >to create this comma-delimited String? Of course, but using a for loop
            >would
            >require me to either include an if statement determining when I am at the
            >last value or manually remove the comma from the end of the String. I
            >figured if I could just use the String.Join instead, I wouldn't have to
            >deal
            >with so many Strings and If statements. And, even though it may be just a
            >thirst for knowledge, I would like to know how to use the ForEach method
            >for
            >future reference. Thanks.
            >--
            >Nathan Sokalski
            >njsokalski@hotm ail.com
            >http://www.nathansokalski.com/
            >>
            >"ModelBuilde r" <ModelBuilder@d iscussions.micr osoft.comwrote in message
            >news:5E4EACC E-CF4D-4FA6-B2BB-51B8082841C8@mi crosoft.com...
            The Action type for the ForEach method requires a subroutine that takes
            no
            parameters. I've never tried this method, but it doesn't seem useful
            for
            your situation. How about starting with the following:
            >
            >
            For Each dayofweek As String In _
            System.Globaliz ation.DateTimeF ormatInfo.Curre ntInfo.DayNames
            >
            Console.Out.Wri teLine(AddQuote s(dayofweek))
            Next
            >
            >
            "Nathan Sokalski" wrote:
            >
            >I am trying to use the System.Array.Fo rEach method in VB.NET. The
            >action
            >that I want to perform on each of the Array values is:
            >>
            >Private Function AddQuotes(ByVal value As String) As String
            > Return String.Format(" '{0}'", value)
            >End Function
            >>
            >Basically, I just want to surround each value with single quotes.
            >However, I
            >am having trouble getting this to work using the System.Array.Fo rEach
            >method. This may be partially because I am not very experienced with
            >Actions
            >or Delegates, so if somebody could tell me what I am doing wrong, I
            >would
            >appreciate it. Thanks. (NOTE: The Array that I want to modify the
            >values
            >of
            >is not one that I have permission to modify (it is
            >System.Globali zation.DateTime FormatInfo.Curr entInfo.DayName s()), so if
            >anybody knows of a way to do this inline without declaring another
            >Array,
            >that would be nice as well)
            >--
            >Nathan Sokalski
            >njsokalski@hotm ail.com
            >http://www.nathansokalski.com/
            >>
            >>
            >>
            >>
            >>
            >>

            Comment

            • Stephany Young

              #7
              Re: Trouble Using System.Array.Fo rEach

              What is so evil about using a loop?


              "Nathan Sokalski" <njsokalski@hot mail.comwrote in message
              news:eQATjud7HH A.4476@TK2MSFTN GP06.phx.gbl...
              >I know how to do string manipulation, that is a very simple task. However,
              >in several of my cases I want to not only add quotes to each element, but
              >take the substring of it as well (for example, in some cases I want an
              >array of only the first letter of each day). The techniques people have
              >mentioned so far are great when I want the entire name, but when I need to
              >do something like get just the first letter, or if I want it in all
              >capitals, etc., I would require either a loop of some sort (which is what I
              >am trying to avoid) or the ForEach method. I appreciate everyone's
              >suggestions on how to use loops and string manipulation, but unfortunately
              >(well, fortunately actually) I already know those techniques. So unless you
              >are going to help me figure out how to use ForEach, save yourself the
              >effort of showing me string manipulation and help someone else that is
              >still learning loops and all the string manipulation techniques. But I
              >still thank you for your time and effort.
              --
              Nathan Sokalski
              njsokalski@hotm ail.com
              有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。

              >
              "ModelBuild er" <ModelBuilder@d iscussions.micr osoft.comwrote in message
              news:19073C71-3202-4285-BBEB-59A81BDCF386@mi crosoft.com...
              >This will avoid the leading comma:
              >>
              >>
              >dim n as integer = CurrentInfo.Day Names.Length - 1
              >dim s as string = CurrentInfo.Day Names(0)
              >>
              >for i = 1 to n
              > s = string.Format(" {0}, {1}", s, CurrentInfo.Day Names(i))
              >next
              >>
              >>
              >"Nathan Sokalski" wrote:
              >>
              >>That would get me the quotes around each of the days, but I was hoping
              >>to do
              >>something like this:
              >>>
              >>String.Join(" ,",System.Globa lization.DateTi meFormatInfo.Cu rrentInfo.DayNa mes())
              >>>
              >>so that I could have the DayNames separated by commas. However, the code
              >>that I have above would not place each day inside quotes. Do I know of
              >>ways
              >>to create this comma-delimited String? Of course, but using a for loop
              >>would
              >>require me to either include an if statement determining when I am at
              >>the
              >>last value or manually remove the comma from the end of the String. I
              >>figured if I could just use the String.Join instead, I wouldn't have to
              >>deal
              >>with so many Strings and If statements. And, even though it may be just
              >>a
              >>thirst for knowledge, I would like to know how to use the ForEach method
              >>for
              >>future reference. Thanks.
              >>--
              >>Nathan Sokalski
              >>njsokalski@hotm ail.com
              >>http://www.nathansokalski.com/
              >>>
              >>"ModelBuilder " <ModelBuilder@d iscussions.micr osoft.comwrote in message
              >>news:5E4EAC CE-CF4D-4FA6-B2BB-51B8082841C8@mi crosoft.com...
              >The Action type for the ForEach method requires a subroutine that
              >takes no
              >parameters. I've never tried this method, but it doesn't seem useful
              >for
              >your situation. How about starting with the following:
              >>
              >>
              > For Each dayofweek As String In _
              >>
              >System.Globali zation.DateTime FormatInfo.Curr entInfo.DayName s
              >>
              > Console.Out.Wri teLine(AddQuote s(dayofweek))
              > Next
              >>
              >>
              >"Nathan Sokalski" wrote:
              >>
              >>I am trying to use the System.Array.Fo rEach method in VB.NET. The
              >>action
              >>that I want to perform on each of the Array values is:
              >>>
              >>Private Function AddQuotes(ByVal value As String) As String
              >> Return String.Format(" '{0}'", value)
              >>End Function
              >>>
              >>Basically, I just want to surround each value with single quotes.
              >>However, I
              >>am having trouble getting this to work using the System.Array.Fo rEach
              >>method. This may be partially because I am not very experienced with
              >>Actions
              >>or Delegates, so if somebody could tell me what I am doing wrong, I
              >>would
              >>appreciate it. Thanks. (NOTE: The Array that I want to modify the
              >>values
              >>of
              >>is not one that I have permission to modify (it is
              >>System.Global ization.DateTim eFormatInfo.Cur rentInfo.DayNam es()), so
              >>if
              >>anybody knows of a way to do this inline without declaring another
              >>Array,
              >>that would be nice as well)
              >>--
              >>Nathan Sokalski
              >>njsokalski@hotm ail.com
              >>http://www.nathansokalski.com/
              >>>
              >>>
              >>>
              >>>
              >>>
              >>>
              >
              >

              Comment

              • =?Utf-8?B?TW9kZWxCdWlsZGVy?=

                #8
                Re: Trouble Using System.Array.Fo rEach

                It appeared from your last question, that you thought using a loop to build
                the comma separated list would require an if-then clause to remove the comma
                before the first iteration. The code I provided eliminates this.

                You have shown several cases where you seem to want a solution "of a
                particular form", rather than a solution. Perhaps someone can post an
                example where Array.ForEach solved a problem for them, but to be honest with
                you, I have never run into a case where it helped. I think if someone has an
                example, it won't exactly fit your conditions.

                "Nathan Sokalski" wrote:
                I know how to do string manipulation, that is a very simple task. However,
                in several of my cases I want to not only add quotes to each element, but
                take the substring of it as well (for example, in some cases I want an array
                of only the first letter of each day). The techniques people have mentioned
                so far are great when I want the entire name, but when I need to do
                something like get just the first letter, or if I want it in all capitals,
                etc., I would require either a loop of some sort (which is what I am trying
                to avoid) or the ForEach method. I appreciate everyone's suggestions on how
                to use loops and string manipulation, but unfortunately (well, fortunately
                actually) I already know those techniques. So unless you are going to help
                me figure out how to use ForEach, save yourself the effort of showing me
                string manipulation and help someone else that is still learning loops and
                all the string manipulation techniques. But I still thank you for your time
                and effort.
                --
                Nathan Sokalski
                njsokalski@hotm ail.com
                有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。

                >
                "ModelBuild er" <ModelBuilder@d iscussions.micr osoft.comwrote in message
                news:19073C71-3202-4285-BBEB-59A81BDCF386@mi crosoft.com...
                This will avoid the leading comma:


                dim n as integer = CurrentInfo.Day Names.Length - 1
                dim s as string = CurrentInfo.Day Names(0)

                for i = 1 to n
                s = string.Format(" {0}, {1}", s, CurrentInfo.Day Names(i))
                next


                "Nathan Sokalski" wrote:
                That would get me the quotes around each of the days, but I was hoping to
                do
                something like this:
                >
                String.Join("," ,System.Globali zation.DateTime FormatInfo.Curr entInfo.DayName s())
                >
                so that I could have the DayNames separated by commas. However, the code
                that I have above would not place each day inside quotes. Do I know of
                ways
                to create this comma-delimited String? Of course, but using a for loop
                would
                require me to either include an if statement determining when I am at the
                last value or manually remove the comma from the end of the String. I
                figured if I could just use the String.Join instead, I wouldn't have to
                deal
                with so many Strings and If statements. And, even though it may be just a
                thirst for knowledge, I would like to know how to use the ForEach method
                for
                future reference. Thanks.
                --
                Nathan Sokalski
                njsokalski@hotm ail.com
                有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。

                >
                "ModelBuild er" <ModelBuilder@d iscussions.micr osoft.comwrote in message
                news:5E4EACCE-CF4D-4FA6-B2BB-51B8082841C8@mi crosoft.com...
                The Action type for the ForEach method requires a subroutine that takes
                no
                parameters. I've never tried this method, but it doesn't seem useful
                for
                your situation. How about starting with the following:


                For Each dayofweek As String In _
                System.Globaliz ation.DateTimeF ormatInfo.Curre ntInfo.DayNames

                Console.Out.Wri teLine(AddQuote s(dayofweek))
                Next


                "Nathan Sokalski" wrote:

                I am trying to use the System.Array.Fo rEach method in VB.NET. The
                action
                that I want to perform on each of the Array values is:
                >
                Private Function AddQuotes(ByVal value As String) As String
                Return String.Format(" '{0}'", value)
                End Function
                >
                Basically, I just want to surround each value with single quotes.
                However, I
                am having trouble getting this to work using the System.Array.Fo rEach
                method. This may be partially because I am not very experienced with
                Actions
                or Delegates, so if somebody could tell me what I am doing wrong, I
                would
                appreciate it. Thanks. (NOTE: The Array that I want to modify the
                values
                of
                is not one that I have permission to modify (it is
                System.Globaliz ation.DateTimeF ormatInfo.Curre ntInfo.DayNames ()), so if
                anybody knows of a way to do this inline without declaring another
                Array,
                that would be nice as well)
                --
                Nathan Sokalski
                njsokalski@hotm ail.com
                有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。

                >
                >
                >
                >
                >
                >
                >
                >
                >

                Comment

                • Nathan Sokalski

                  #9
                  Re: Trouble Using System.Array.Fo rEach

                  You are definitely correct that you proved me wrong about the loop thing, at
                  least for the scenario of simply adding quotes, thank you very much for
                  providing that solution. However, I still have the scenarios where I need to
                  use only the first letter, or the first two letters, or capitalize, etc.,
                  and your solution does not work for these (unless I'm missing something
                  again), which I think are the scenarios I was thinking about when I
                  mentioned the If Then statement. And you may be right about the ForEach not
                  fitting my conditions, I really can't say for sure since I have never had
                  the opportunity to use ForEach, but either way, it never hurts to have extra
                  knowledge so that if a situation were to come up where it was fit I would
                  know it. Thanks.
                  --
                  Nathan Sokalski
                  njsokalski@hotm ail.com
                  有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。


                  "ModelBuild er" <ModelBuilder@d iscussions.micr osoft.comwrote in message
                  news:EA14ADC5-F596-47DB-AE63-793851793A56@mi crosoft.com...
                  It appeared from your last question, that you thought using a loop to
                  build
                  the comma separated list would require an if-then clause to remove the
                  comma
                  before the first iteration. The code I provided eliminates this.
                  >
                  You have shown several cases where you seem to want a solution "of a
                  particular form", rather than a solution. Perhaps someone can post an
                  example where Array.ForEach solved a problem for them, but to be honest
                  with
                  you, I have never run into a case where it helped. I think if someone has
                  an
                  example, it won't exactly fit your conditions.
                  >
                  "Nathan Sokalski" wrote:
                  >
                  >I know how to do string manipulation, that is a very simple task.
                  >However,
                  >in several of my cases I want to not only add quotes to each element, but
                  >take the substring of it as well (for example, in some cases I want an
                  >array
                  >of only the first letter of each day). The techniques people have
                  >mentioned
                  >so far are great when I want the entire name, but when I need to do
                  >something like get just the first letter, or if I want it in all
                  >capitals,
                  >etc., I would require either a loop of some sort (which is what I am
                  >trying
                  >to avoid) or the ForEach method. I appreciate everyone's suggestions on
                  >how
                  >to use loops and string manipulation, but unfortunately (well,
                  >fortunately
                  >actually) I already know those techniques. So unless you are going to
                  >help
                  >me figure out how to use ForEach, save yourself the effort of showing me
                  >string manipulation and help someone else that is still learning loops
                  >and
                  >all the string manipulation techniques. But I still thank you for your
                  >time
                  >and effort.
                  >--
                  >Nathan Sokalski
                  >njsokalski@hotm ail.com
                  >http://www.nathansokalski.com/
                  >>
                  >"ModelBuilde r" <ModelBuilder@d iscussions.micr osoft.comwrote in message
                  >news:19073C7 1-3202-4285-BBEB-59A81BDCF386@mi crosoft.com...
                  This will avoid the leading comma:
                  >
                  >
                  dim n as integer = CurrentInfo.Day Names.Length - 1
                  dim s as string = CurrentInfo.Day Names(0)
                  >
                  for i = 1 to n
                  s = string.Format(" {0}, {1}", s, CurrentInfo.Day Names(i))
                  next
                  >
                  >
                  "Nathan Sokalski" wrote:
                  >
                  >That would get me the quotes around each of the days, but I was hoping
                  >to
                  >do
                  >something like this:
                  >>
                  >String.Join(", ",System.Global ization.DateTim eFormatInfo.Cur rentInfo.DayNam es())
                  >>
                  >so that I could have the DayNames separated by commas. However, the
                  >code
                  >that I have above would not place each day inside quotes. Do I know of
                  >ways
                  >to create this comma-delimited String? Of course, but using a for loop
                  >would
                  >require me to either include an if statement determining when I am at
                  >the
                  >last value or manually remove the comma from the end of the String. I
                  >figured if I could just use the String.Join instead, I wouldn't have
                  >to
                  >deal
                  >with so many Strings and If statements. And, even though it may be
                  >just a
                  >thirst for knowledge, I would like to know how to use the ForEach
                  >method
                  >for
                  >future reference. Thanks.
                  >--
                  >Nathan Sokalski
                  >njsokalski@hotm ail.com
                  >http://www.nathansokalski.com/
                  >>
                  >"ModelBuilde r" <ModelBuilder@d iscussions.micr osoft.comwrote in
                  >message
                  >news:5E4EACC E-CF4D-4FA6-B2BB-51B8082841C8@mi crosoft.com...
                  The Action type for the ForEach method requires a subroutine that
                  takes
                  no
                  parameters. I've never tried this method, but it doesn't seem
                  useful
                  for
                  your situation. How about starting with the following:
                  >
                  >
                  For Each dayofweek As String In _
                  >
                  System.Globaliz ation.DateTimeF ormatInfo.Curre ntInfo.DayNames
                  >
                  Console.Out.Wri teLine(AddQuote s(dayofweek))
                  Next
                  >
                  >
                  "Nathan Sokalski" wrote:
                  >
                  >I am trying to use the System.Array.Fo rEach method in VB.NET. The
                  >action
                  >that I want to perform on each of the Array values is:
                  >>
                  >Private Function AddQuotes(ByVal value As String) As String
                  > Return String.Format(" '{0}'", value)
                  >End Function
                  >>
                  >Basically, I just want to surround each value with single quotes.
                  >However, I
                  >am having trouble getting this to work using the
                  >System.Array.F orEach
                  >method. This may be partially because I am not very experienced
                  >with
                  >Actions
                  >or Delegates, so if somebody could tell me what I am doing wrong, I
                  >would
                  >appreciate it. Thanks. (NOTE: The Array that I want to modify the
                  >values
                  >of
                  >is not one that I have permission to modify (it is
                  >System.Globali zation.DateTime FormatInfo.Curr entInfo.DayName s()), so
                  >if
                  >anybody knows of a way to do this inline without declaring another
                  >Array,
                  >that would be nice as well)
                  >--
                  >Nathan Sokalski
                  >njsokalski@hotm ail.com
                  >http://www.nathansokalski.com/
                  >>
                  >>
                  >>
                  >>
                  >>
                  >>
                  >>
                  >>
                  >>

                  Comment

                  • Nathan Sokalski

                    #10
                    Re: Trouble Using System.Array.Fo rEach

                    I have nothing against loops, in fact in many cases, I try to use them to if
                    it can reduce the size of my code, but in this case, I could end up removing
                    both a loop and an if-then, as well as some string manipulation. So in this
                    case, I think the ForEach would shrink my code more than a loop. I feel
                    loops are very important and useful, but in this case I think I could do
                    better, as well as the fact that I want to learn certain things, and not
                    everything is included in the books I have (and I have a reasonable number,
                    and have read them cover to cover). I appreciate any and all help you can
                    give.
                    --
                    Nathan Sokalski
                    njsokalski@hotm ail.com
                    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。


                    "Stephany Young" <noone@localhos twrote in message
                    news:uj9EgJg7HH A.3716@TK2MSFTN GP03.phx.gbl...
                    What is so evil about using a loop?
                    >
                    >
                    "Nathan Sokalski" <njsokalski@hot mail.comwrote in message
                    news:eQATjud7HH A.4476@TK2MSFTN GP06.phx.gbl...
                    >>I know how to do string manipulation, that is a very simple task. However,
                    >>in several of my cases I want to not only add quotes to each element, but
                    >>take the substring of it as well (for example, in some cases I want an
                    >>array of only the first letter of each day). The techniques people have
                    >>mentioned so far are great when I want the entire name, but when I need to
                    >>do something like get just the first letter, or if I want it in all
                    >>capitals, etc., I would require either a loop of some sort (which is what
                    >>I am trying to avoid) or the ForEach method. I appreciate everyone's
                    >>suggestions on how to use loops and string manipulation, but unfortunately
                    >>(well, fortunately actually) I already know those techniques. So unless
                    >>you are going to help me figure out how to use ForEach, save yourself the
                    >>effort of showing me string manipulation and help someone else that is
                    >>still learning loops and all the string manipulation techniques. But I
                    >>still thank you for your time and effort.
                    >--
                    >Nathan Sokalski
                    >njsokalski@hotm ail.com
                    >http://www.nathansokalski.com/
                    >>
                    >"ModelBuilde r" <ModelBuilder@d iscussions.micr osoft.comwrote in message
                    >news:19073C7 1-3202-4285-BBEB-59A81BDCF386@mi crosoft.com...
                    >>This will avoid the leading comma:
                    >>>
                    >>>
                    >>dim n as integer = CurrentInfo.Day Names.Length - 1
                    >>dim s as string = CurrentInfo.Day Names(0)
                    >>>
                    >>for i = 1 to n
                    >> s = string.Format(" {0}, {1}", s, CurrentInfo.Day Names(i))
                    >>next
                    >>>
                    >>>
                    >>"Nathan Sokalski" wrote:
                    >>>
                    >>>That would get me the quotes around each of the days, but I was hoping
                    >>>to do
                    >>>something like this:
                    >>>>
                    >>>String.Join( ",",System.Glob alization.DateT imeFormatInfo.C urrentInfo.DayN ames())
                    >>>>
                    >>>so that I could have the DayNames separated by commas. However, the
                    >>>code
                    >>>that I have above would not place each day inside quotes. Do I know of
                    >>>ways
                    >>>to create this comma-delimited String? Of course, but using a for loop
                    >>>would
                    >>>require me to either include an if statement determining when I am at
                    >>>the
                    >>>last value or manually remove the comma from the end of the String. I
                    >>>figured if I could just use the String.Join instead, I wouldn't have to
                    >>>deal
                    >>>with so many Strings and If statements. And, even though it may be just
                    >>>a
                    >>>thirst for knowledge, I would like to know how to use the ForEach
                    >>>method for
                    >>>future reference. Thanks.
                    >>>--
                    >>>Nathan Sokalski
                    >>>njsokalski@hotm ail.com
                    >>>http://www.nathansokalski.com/
                    >>>>
                    >>>"ModelBuilde r" <ModelBuilder@d iscussions.micr osoft.comwrote in
                    >>>message
                    >>>news:5E4EACC E-CF4D-4FA6-B2BB-51B8082841C8@mi crosoft.com...
                    >>The Action type for the ForEach method requires a subroutine that
                    >>takes no
                    >>parameters. I've never tried this method, but it doesn't seem useful
                    >>for
                    >>your situation. How about starting with the following:
                    >>>
                    >>>
                    >> For Each dayofweek As String In _
                    >>>
                    >>System.Global ization.DateTim eFormatInfo.Cur rentInfo.DayNam es
                    >>>
                    >> Console.Out.Wri teLine(AddQuote s(dayofweek))
                    >> Next
                    >>>
                    >>>
                    >>"Nathan Sokalski" wrote:
                    >>>
                    >>>I am trying to use the System.Array.Fo rEach method in VB.NET. The
                    >>>action
                    >>>that I want to perform on each of the Array values is:
                    >>>>
                    >>>Private Function AddQuotes(ByVal value As String) As String
                    >>> Return String.Format(" '{0}'", value)
                    >>>End Function
                    >>>>
                    >>>Basically, I just want to surround each value with single quotes.
                    >>>However, I
                    >>>am having trouble getting this to work using the
                    >>>System.Array .ForEach
                    >>>method. This may be partially because I am not very experienced with
                    >>>Actions
                    >>>or Delegates, so if somebody could tell me what I am doing wrong, I
                    >>>would
                    >>>appreciate it. Thanks. (NOTE: The Array that I want to modify the
                    >>>values
                    >>>of
                    >>>is not one that I have permission to modify (it is
                    >>>System.Globa lization.DateTi meFormatInfo.Cu rrentInfo.DayNa mes()), so
                    >>>if
                    >>>anybody knows of a way to do this inline without declaring another
                    >>>Array,
                    >>>that would be nice as well)
                    >>>--
                    >>>Nathan Sokalski
                    >>>njsokalski@hotm ail.com
                    >>>http://www.nathansokalski.com/
                    >>>>
                    >>>>
                    >>>>
                    >>>>
                    >>>>
                    >>>>
                    >>
                    >>
                    >

                    Comment

                    Working...