473,388 Members | 1,198 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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
Dec 11 '07 #1
12 1909
"Robert Scheer" <rb******@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.TrueForAll(s.ToCharArray, Function(c As Char) (c = s(0)))

(VB 2008)
Armin
Dec 11 '07 #2

"Armin Zingler" <az*******@freenet.dekirjoitti viestissä
news:eO**************@TK2MSFTNGP04.phx.gbl...
"Robert Scheer" <rb******@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.Substring(0, 1), "") = ""

Doesn't need VB 2008.

-Teemu

Dec 11 '07 #3


"Teemu" wrote:
>
"Armin Zingler" <az*******@freenet.dekirjoitti viestissä
news:eO**************@TK2MSFTNGP04.phx.gbl...
"Robert Scheer" <rb******@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.Substring(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.
>
Dec 11 '07 #4

"Family Tree Mike" <Fa************@discussions.microsoft.comkirjoit ti
viestissä news:6E**********************************@microsof t.com...
>

"Teemu" wrote:
>>
"Armin Zingler" <az*******@freenet.dekirjoitti viestissä
news:eO**************@TK2MSFTNGP04.phx.gbl...
"Robert Scheer" <rb******@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.Substring(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.Substring(0, 1),
"") = ""

-Teemu

Dec 11 '07 #5
"Family Tree Mike" <Fa************@discussions.microsoft.comschrieb
>
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".IndexOf(s(0)) -1 _
AndAlso _
Array.TrueForAll(s.ToCharArray, Function(c As Char) (c = s(0)))
Better? ;-)
Armin
Dec 11 '07 #6


"Armin Zingler" wrote:
"Family Tree Mike" <Fa************@discussions.microsoft.comschrieb

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".IndexOf(s(0)) -1 _
AndAlso _
Array.TrueForAll(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.

Dec 11 '07 #7
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...

Dec 11 '07 #8
"Family Tree Mike" <Fa************@discussions.microsoft.comschrieb
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.CompilerServices.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.CompilerServices.Extension()_
Public Function EqualDigitsOnly(ByVal s As String) As Boolean

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

End Function
Call:
b = s.Length = 7 AndAlso s.EqualDigitsOnly

;-)
Armin
Dec 11 '07 #9


"Armin Zingler" wrote:
"Family Tree Mike" <Fa************@discussions.microsoft.comschrieb
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.CompilerServices.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.CompilerServices.Extension()_
Public Function EqualDigitsOnly(ByVal s As String) As Boolean

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

End Function
Call:
b = s.Length = 7 AndAlso s.EqualDigitsOnly

;-)
Armin
Thanks! I didn't realize VB allowed for this!
Dec 11 '07 #10
On 2007-12-11, Family Tree Mike <Fa************@discussions.microsoft.comwrote:
>

"Armin Zingler" wrote:
>"Family Tree Mike" <Fa************@discussions.microsoft.comschrieb
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.CompilerServices.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.CompilerServices.Extension()_
Public Function EqualDigitsOnly(ByVal s As String) As Boolean

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

End Function
Call:
b = s.Length = 7 AndAlso s.EqualDigitsOnly

;-)
Armin

Thanks! I didn't realize VB allowed for this!

2008 does. It has to, to support LINQ.

--
Tom Shelton
Dec 11 '07 #11
what about this?

Private Function TrueForAll(ByVal 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" <rb******@my-deja.comschreef in bericht
news:7c**********************************@s8g2000p rg.googlegroups.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

Dec 13 '07 #12
perhaps, if necessary, a litle correction if the number must be different
from zero

what about this?

Private Function TrueForAll(ByVal 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" <an*****@pandora.beschreef in bericht
news:fa**********************@phobos.telenet-ops.be...
what about this?

Private Function TrueForAll(ByVal 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" <rb******@my-deja.comschreef in bericht
news:7c**********************************@s8g2000p rg.googlegroups.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


Dec 13 '07 #13

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

Similar topics

9
by: Leif K-Brooks | last post by:
How do I make a regular expression which will match the same character repeated one or more times, instead of matching repetitions of any (possibly non-same) characters like ".+" does? In other...
0
by: Wolfgang Lipp | last post by:
From: Lipp, Wolfgang Sent: Tuesday, 27?January?2004 13:26 <annotation> the first eleven contributions in this thread started as an off-list email discussion; i have posted them here with...
9
by: Harsha Srinath | last post by:
Athough this might not be directly relayed to C syntax, I thought some of you may find this an interesting problem :- 1.One number, in an array integers from 1 to 1,000,000 is present twice. How...
1
by: Alec MacLean | last post by:
Hi, Outline of problem: I've built a set of user controls that are used to output questions for a survey and gather the responses using simple radio buttons. I'm adding an optional textbox...
3
by: IraqiAli | last post by:
ok i have a couple of textboxes. The user is required to input values from 1 to 6 into those boxes. and submit it, those values would then go into an array. What i need to do is do checks to make...
7
by: saidingist | last post by:
I'm struggling with writing a code for a project MODE. The program should find the number in an array which repeats the most. For example if you've entered a set of 10 numbers like 1 2 1 2 4 2 5 2 6...
7
by: bagelman | last post by:
Hi, I have a string Array. Its length is 100. I want to search the array to find repeated strings in it. And after finding repeated strings I want to write to screen which word repeated how many...
4
by: rlwebbnafex | last post by:
Hello, I have never used generic programming so I need a little help for an idea on what I can do. I have defined a lot of classes like the following. The classes are all pretty much the same,...
9
by: C#_Help_needed | last post by:
I need help with the following question. THANKS :) Write a program in c# that takes in a directory as a command line parameter, and returns the longest repeated phrase in ALL text files in that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.