473,386 Members | 1,630 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,386 software developers and data experts.

substring

Hi

i have a string value that contains a number this could look like
03843282922132 now the 0 at the beginning is the important bit when using
substring to get every three charachters it misses off the first 0 is there
a way round this or another way of doing it, here is my currect code.

Dim m As String

m = TextBox3.Text

Dim x(m.Length) As Integer

For i As Integer = 0 To m.Length - 1

x(i) = m.Substring(i, 3)

Debug.WriteLine(x(i))

Next

Any help apreciated,

Mike.

Nov 20 '05 #1
2 1315
Dim m As String

m = TextBox1.Text

Dim x As String

For i As Integer = 0 To m.Length - 1

If m.Length - 1 - i > 3 Then

x = m.Substring(i, 3)

Else
x = m.Substring(i, m.Length - 1 - i)
End If

Debug.WriteLine(x)

Next

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:O5**************@tk2msftngp13.phx.gbl...
Hi

i have a string value that contains a number this could look like
03843282922132 now the 0 at the beginning is the important bit when using
substring to get every three charachters it misses off the first 0 is there a way round this or another way of doing it, here is my currect code.

Dim m As String

m = TextBox3.Text

Dim x(m.Length) As Integer

For i As Integer = 0 To m.Length - 1

x(i) = m.Substring(i, 3)

Debug.WriteLine(x(i))

Next

Any help apreciated,

Mike.

Nov 20 '05 #2
"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:O5**************@tk2msftngp13.phx.gbl...
i have a string value that contains a number this could look like
03843282922132 now the 0 at the beginning is the important bit when using substring to get every three charachters it misses off the
first 0
It does no such thing! Follow your own code as it works its magic...
Dim m As String
m = TextBox3.Text
m now contains the String "03843282922132".
Dim x(m.Length) As Integer
NB: Integer *not* String!!
For i As Integer = 0 To m.Length - 1
x(i) = m.Substring(i, 3)
' e.g. x( 0 ) now holds the Integer 38
Debug.WriteLine(x(i))
Next


Each trio of digits is being "Evilly Type Coerced" from a String into
an Integer and, of course, Integers don't have leading zeroes - only
the String /representations/ of them do.
If you /want/ leading zeroes, keep them as Strings; if you want to
have numbers that you /display/ as Strings, do so, as in

For i As Integer = 0 To m.Length - 1
x( i ) = CInt( m.Substring( i, 3 ) )
Debug.WriteLine( x( i ).ToString( "000" ) )
Next

BTW, please, please *please*, put

Option Strict On

at the top of your source file (or set it in the default project settings).
I cannot recommend its use strongly enough.

It /will/ break a lot of your code but, by the time you've fixed them
all, you'll understand type conversion much, /much/ better.

HTH,
Phill W.
Nov 20 '05 #3

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

Similar topics

7
by: Don Freeman | last post by:
Seems like whatever value I use for the first int field (starting position) the substring procedure negates it and triggers a String index out of range error. I've tried all sorts of work...
7
by: Radhika Sambamurti | last post by:
Hi, I've written a substring function. The prototype is: int substr(char s1, char s2) Returns 1 if s2 is a substring of s1, else it returns 0. I have written this program, but Im sure there is an...
1
by: sysindex | last post by:
I am trying to find a way to dynamically retrieve the substring starting point of an nText field. My query looks something like SELECT ID,Substring(DOCTEXT,0,200) from mytable where DOCTEXT...
11
by: Darren Anderson | last post by:
I have a function that I've tried using in an if then statement and I've found that no matter how much reworking I do with the code, the expected result is incorrect. the code: If Not...
5
by: btober | last post by:
I can't seem to get right the regular expression for parsing data like these four sample rows (names and addresses changed to ficticious values) from a text-type column: Yolanda Harris, 38, of...
2
by: mallard134 | last post by:
Could someone please help a newbee vb programmer with a question that is driving me crazy. I am trying to understand a line of code that is supposed to return the domain portion of a valid email...
4
by: Jean-François Michaud | last post by:
Hello, I've been looking at this for a bit now and I don't see what's wrong with the code. Can anybody see a problem with this? Here is an XSLT snippet I use. <xsl:template match="graphic">...
6
by: kellygreer1 | last post by:
What is a good one line method for doing a "length safe" String.Substring? The VB classes offer up the old Left function so that string s = Microsoft.VisualBasic.Left("kelly",200) // s will =...
11
by: dyc | last post by:
how do i make use of substring method in order to extract the specified data from a a long string? I also need to do some checking b4 extracting the data, for instance: it only will extract the...
3
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
Two part question: 1. Is Regex more efficient than manually comparing values using Substring? 2. I've never created a Regex expression. How would I use regex to do the equivalent of what I...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.