Repeated numbers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Scheer

    Repeated numbers

    Hi.

    I am trying to write a boolean function that checks if the user
    entered a sequence with 7 equal numbers, eg: 1111111, 2222222, 3333333
    and so on. How can I do this in VB.NET ?

    Thanks,
    Robert Scheer
  • Armin Zingler

    #2
    Re: Repeated numbers

    "Robert Scheer" <rbscheer@my-deja.comschrieb
    Hi.
    >
    I am trying to write a boolean function that checks if the user
    entered a sequence with 7 equal numbers, eg: 1111111, 2222222,
    3333333 and so on. How can I do this in VB.NET ?

    Dim s As String = "1111111"
    Dim b As Boolean

    b = _
    s.length = 7 _
    andalso _
    Array.TrueForAl l(s.ToCharArray , Function(c As Char) (c = s(0)))

    (VB 2008)


    Armin

    Comment

    • Teemu

      #3
      Re: Repeated numbers


      "Armin Zingler" <az.nospam@free net.dekirjoitti viestissä
      news:eO3vsY$OIH A.4712@TK2MSFTN GP04.phx.gbl...
      "Robert Scheer" <rbscheer@my-deja.comschrieb
      >Hi.
      >>
      >I am trying to write a boolean function that checks if the user
      >entered a sequence with 7 equal numbers, eg: 1111111, 2222222,
      >3333333 and so on. How can I do this in VB.NET ?
      Another solution:

      Dim a As String = "1111111"
      Dim b As Boolean = False

      b = a.Length = 7 AndAlso a.Replace(a.Sub string(0, 1), "") = ""

      Doesn't need VB 2008.

      -Teemu

      Comment

      • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

        #4
        Re: Repeated numbers



        "Teemu" wrote:
        >
        "Armin Zingler" <az.nospam@free net.dekirjoitti viestissä
        news:eO3vsY$OIH A.4712@TK2MSFTN GP04.phx.gbl...
        "Robert Scheer" <rbscheer@my-deja.comschrieb
        Hi.
        >
        I am trying to write a boolean function that checks if the user
        entered a sequence with 7 equal numbers, eg: 1111111, 2222222,
        3333333 and so on. How can I do this in VB.NET ?
        >
        Another solution:
        >
        Dim a As String = "1111111"
        Dim b As Boolean = False
        >
        b = a.Length = 7 AndAlso a.Replace(a.Sub string(0, 1), "") = ""
        >
        Doesn't need VB 2008.
        >
        -Teemu
        >
        But both of these codes evaluate to true for the string "AAAAAAA". I guess
        the original poster should have some of the fun catching this case.
        >

        Comment

        • Teemu

          #5
          Re: Repeated numbers


          "Family Tree Mike" <FamilyTreeMike @discussions.mi crosoft.comkirj oitti
          viestissä news:6EC0389C-6532-410A-BC38-B610FD0F188C@mi crosoft.com...
          >
          >
          "Teemu" wrote:
          >
          >>
          >"Armin Zingler" <az.nospam@free net.dekirjoitti viestissä
          >news:eO3vsY$OI HA.4712@TK2MSFT NGP04.phx.gbl.. .
          "Robert Scheer" <rbscheer@my-deja.comschrieb
          >Hi.
          >>
          >I am trying to write a boolean function that checks if the user
          >entered a sequence with 7 equal numbers, eg: 1111111, 2222222,
          >3333333 and so on. How can I do this in VB.NET ?
          >>
          >Another solution:
          >>
          >Dim a As String = "1111111"
          >Dim b As Boolean = False
          >>
          >b = a.Length = 7 AndAlso a.Replace(a.Sub string(0, 1), "") = ""
          >>
          But both of these codes evaluate to true for the string "AAAAAAA". I
          guess
          the original poster should have some of the fun catching this case.
          That's easy:

          b = a.Length = 7 AndAlso IsNumeric(a) AndAlso a.Replace(a.Sub string(0, 1),
          "") = ""

          -Teemu

          Comment

          • Armin Zingler

            #6
            Re: Repeated numbers

            "Family Tree Mike" <FamilyTreeMike @discussions.mi crosoft.comschr ieb
            >
            But both of these codes evaluate to true for the string "AAAAAAA".
            I guess the original poster should have some of the fun catching
            this case.

            You're right.

            b = _
            s.Length = 7 _
            AndAlso _
            "0123456789".In dexOf(s(0)) -1 _
            AndAlso _
            Array.TrueForAl l(s.ToCharArray , Function(c As Char) (c = s(0)))


            Better? ;-)


            Armin

            Comment

            • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

              #7
              Re: Repeated numbers



              "Armin Zingler" wrote:
              "Family Tree Mike" <FamilyTreeMike @discussions.mi crosoft.comschr ieb

              But both of these codes evaluate to true for the string "AAAAAAA".
              I guess the original poster should have some of the fun catching
              this case.
              >
              >
              You're right.
              >
              b = _
              s.Length = 7 _
              AndAlso _
              "0123456789".In dexOf(s(0)) -1 _
              AndAlso _
              Array.TrueForAl l(s.ToCharArray , Function(c As Char) (c = s(0)))
              >
              >
              Better? ;-)
              >
              >
              Armin
              >
              You both got it! I prefer the VB 2008 way (TrueForAll), but I may have gone
              for an extension method to string.

              Comment

              • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

                #8
                Re: Repeated numbers

                You both got it! I prefer the VB 2008 way (TrueForAll), but I may have gone
                for an extension method to string.
                >
                Sorry, the C# side of me slipped out...

                Comment

                • Armin Zingler

                  #9
                  Re: Repeated numbers

                  "Family Tree Mike" <FamilyTreeMike @discussions.mi crosoft.comschr ieb
                  You both got it! I prefer the VB 2008 way (TrueForAll), but I may
                  have gone for an extension method to string.
                  >
                  Sorry, the C# side of me slipped out...
                  Ok, let's extend this thread to extensions.... ;)


                  <System.Runtime .CompilerServic es.Extension()_
                  Public Function TrueForAll( _
                  ByVal s As String, ByVal match As Predicate(Of Char)) _
                  As Boolean
                  For Each c In s
                  If Not match(c) Then Return False
                  Next
                  Return True
                  End Function

                  <System.Runtime .CompilerServic es.Extension()_
                  Public Function EqualDigitsOnly (ByVal s As String) As Boolean

                  Return Char.IsDigit(s( 0)) _
                  AndAlso _
                  s.TrueForAll(Fu nction(c As Char) (c = s(0)))

                  End Function


                  Call:
                  b = s.Length = 7 AndAlso s.EqualDigitsOn ly

                  ;-)


                  Armin

                  Comment

                  • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

                    #10
                    Re: Repeated numbers



                    "Armin Zingler" wrote:
                    "Family Tree Mike" <FamilyTreeMike @discussions.mi crosoft.comschr ieb
                    You both got it! I prefer the VB 2008 way (TrueForAll), but I may
                    have gone for an extension method to string.
                    >
                    Sorry, the C# side of me slipped out...
                    >
                    Ok, let's extend this thread to extensions.... ;)
                    >
                    >
                    <System.Runtime .CompilerServic es.Extension()_
                    Public Function TrueForAll( _
                    ByVal s As String, ByVal match As Predicate(Of Char)) _
                    As Boolean
                    For Each c In s
                    If Not match(c) Then Return False
                    Next
                    Return True
                    End Function
                    >
                    <System.Runtime .CompilerServic es.Extension()_
                    Public Function EqualDigitsOnly (ByVal s As String) As Boolean
                    >
                    Return Char.IsDigit(s( 0)) _
                    AndAlso _
                    s.TrueForAll(Fu nction(c As Char) (c = s(0)))
                    >
                    End Function
                    >
                    >
                    Call:
                    b = s.Length = 7 AndAlso s.EqualDigitsOn ly
                    >
                    ;-)
                    >
                    >
                    Armin
                    >
                    Thanks! I didn't realize VB allowed for this!


                    Comment

                    • Tom Shelton

                      #11
                      Re: Repeated numbers

                      On 2007-12-11, Family Tree Mike <FamilyTreeMike @discussions.mi crosoft.comwrot e:
                      >
                      >
                      "Armin Zingler" wrote:
                      >
                      >"Family Tree Mike" <FamilyTreeMike @discussions.mi crosoft.comschr ieb
                      You both got it! I prefer the VB 2008 way (TrueForAll), but I may
                      have gone for an extension method to string.
                      >
                      >
                      Sorry, the C# side of me slipped out...
                      >>
                      >Ok, let's extend this thread to extensions.... ;)
                      >>
                      >>
                      > <System.Runtime .CompilerServic es.Extension()_
                      > Public Function TrueForAll( _
                      > ByVal s As String, ByVal match As Predicate(Of Char)) _
                      > As Boolean
                      > For Each c In s
                      > If Not match(c) Then Return False
                      > Next
                      > Return True
                      > End Function
                      >>
                      > <System.Runtime .CompilerServic es.Extension()_
                      > Public Function EqualDigitsOnly (ByVal s As String) As Boolean
                      >>
                      > Return Char.IsDigit(s( 0)) _
                      > AndAlso _
                      > s.TrueForAll(Fu nction(c As Char) (c = s(0)))
                      >>
                      > End Function
                      >>
                      >>
                      >Call:
                      > b = s.Length = 7 AndAlso s.EqualDigitsOn ly
                      >>
                      >;-)
                      >>
                      >>
                      >Armin
                      >>
                      >
                      Thanks! I didn't realize VB allowed for this!
                      >
                      >
                      2008 does. It has to, to support LINQ.

                      --
                      Tom Shelton

                      Comment

                      • andreas

                        #12
                        Re: Repeated numbers

                        what about this?

                        Private Function TrueForAll(ByVa l s As String) As Boolean
                        Return IsNumeric(s) AndAlso Len(s) = 7 _
                        AndAlso Len(CStr(CSng(s )/ 1111111)) = 1
                        End Function

                        very simple of a simple mind


                        "Robert Scheer" <rbscheer@my-deja.comschreef in bericht
                        news:7cf5ee0e-9391-42c7-ab0f-78414c822118@s8 g2000prg.google groups.com...
                        Hi.
                        >
                        I am trying to write a boolean function that checks if the user
                        entered a sequence with 7 equal numbers, eg: 1111111, 2222222, 3333333
                        and so on. How can I do this in VB.NET ?
                        >
                        Thanks,
                        Robert Scheer

                        Comment

                        • andreas

                          #13
                          Re: Repeated numbers

                          perhaps, if necessary, a litle correction if the number must be different
                          from zero

                          what about this?

                          Private Function TrueForAll(ByVa l s As String) As Boolean
                          Return IsNumeric(s) AndAlso Len(s) = 7 _
                          AndAlso Len(CStr(CSng(s )/ 1111111)) = 1 andalso cint(s) 0
                          End Function

                          very simple of a simple mind


                          "andreas" <andreas@pandor a.beschreef in bericht
                          news:faf8j.2543 02$Sv.13366371@ phobos.telenet-ops.be...
                          what about this?
                          >
                          Private Function TrueForAll(ByVa l s As String) As Boolean
                          Return IsNumeric(s) AndAlso Len(s) = 7 _
                          AndAlso Len(CStr(CSng(s )/ 1111111)) = 1
                          End Function
                          >
                          very simple of a simple mind
                          >
                          >
                          "Robert Scheer" <rbscheer@my-deja.comschreef in bericht
                          news:7cf5ee0e-9391-42c7-ab0f-78414c822118@s8 g2000prg.google groups.com...
                          >Hi.
                          >>
                          >I am trying to write a boolean function that checks if the user
                          >entered a sequence with 7 equal numbers, eg: 1111111, 2222222, 3333333
                          >and so on. How can I do this in VB.NET ?
                          >>
                          >Thanks,
                          >Robert Scheer
                          >
                          >

                          Comment

                          Working...