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

Problem with Substing - Index and length must refer to a location

Hello,

I've a strange problem with substring function.
I'm geting a string from my SQL DataBase and i want to split it to two
substings.

here is what i do:

if(temp.Length>80 && temp.Length<=160)
{
line1_txt.Text=temp.Substring(0,79);
line2_txt.Text=temp.Substring(80,temp.Length-1);
}

with line1_txt i have no problem, when i'm getting to line2_txt i get the
error message:

"Index and length must refer to a location within the string."

when i'm giving in line2 the same substring values like in line1 it works.
How can i split this line into two lines?

Thanks,
Gidi.

Jul 21 '06 #1
2 26557
As per the error message (and the .NET documentation), Substring takes a
start index and a length. Not a start index and an end index, which is what
you are trying to give it.

You could also just use the overloaded version which just takes the start
index, and returns the rest of the string (which is what you want for that
second string).

"Gidi" <sh*****@hotmail.com.dontspamwrote in message
news:E1**********************************@microsof t.com...
Hello,

I've a strange problem with substring function.
I'm geting a string from my SQL DataBase and i want to split it to two
substings.

here is what i do:

if(temp.Length>80 && temp.Length<=160)
{
line1_txt.Text=temp.Substring(0,79);
line2_txt.Text=temp.Substring(80,temp.Length-1);
}

with line1_txt i have no problem, when i'm getting to line2_txt i get the
error message:

"Index and length must refer to a location within the string."

when i'm giving in line2 the same substring values like in line1 it works.
How can i split this line into two lines?

Thanks,
Gidi.

Jul 21 '06 #2
Hi Marina,

Thank you very much.

I looked for this solution for so long...

stupid mistake by me... :-)

"Marina Levit [MVP]" wrote:
As per the error message (and the .NET documentation), Substring takes a
start index and a length. Not a start index and an end index, which is what
you are trying to give it.

You could also just use the overloaded version which just takes the start
index, and returns the rest of the string (which is what you want for that
second string).

"Gidi" <sh*****@hotmail.com.dontspamwrote in message
news:E1**********************************@microsof t.com...
Hello,

I've a strange problem with substring function.
I'm geting a string from my SQL DataBase and i want to split it to two
substings.

here is what i do:

if(temp.Length>80 && temp.Length<=160)
{
line1_txt.Text=temp.Substring(0,79);
line2_txt.Text=temp.Substring(80,temp.Length-1);
}

with line1_txt i have no problem, when i'm getting to line2_txt i get the
error message:

"Index and length must refer to a location within the string."

when i'm giving in line2 the same substring values like in line1 it works.
How can i split this line into two lines?

Thanks,
Gidi.


Jul 21 '06 #3

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

Similar topics

4
by: Federico Bari | last post by:
Good morning all from italy, i have probably a compatibility problem with a html/javascript page. The aim of the code of the file test.htm you find here following (copy the 3 files in the...
20
by: titi | last post by:
Question The road and traffic authority for a small country currently uses a system to store information about all 'currently' licensed drivers. A licensed driver has the following info stored...
7
by: Ankit Aneja | last post by:
I put the code for url rewrite in my Application_BeginRequest on global.ascx some .aspx pages are in root ,some in folder named admin and some in folder named user aspx pages which are in user...
2
by: Denis C | last post by:
Hi there, I'm trying to convert part of a byte array into a series of fixed length strings but half way through the for loop I get an error that I'm accessing outside the buffer bounds. The...
18
by: len.hartley | last post by:
Hi, I am trying to pop-up a window when the user clicks on an image. The problem is that when the user clicks on the image and the window pops up OK, but the window underneath also proceeds to...
12
by: NOO Recursion | last post by:
Hi everyone! I am trying to write a program that will search a 12x12 for a thing called a "blob". A blob in the grid is made up of asterisks. A blob contains at least one asterisk. If an...
5
by: althafexcel | last post by:
hi everyone Im trying to include an external js in my aspx page under the head tag, it doesn't load or it displays an object expected error whenver the function from the .js is called. Actually...
0
by: iprogrammer | last post by:
i have a problem when i try to run my windows service ..which is "Error 1053: The service did not respond to the start or control request in a timely fashion" >after this i cannot anything with...
2
by: swethak | last post by:
hi , i write the code in .htm file. It is in cgi-bin/searches/one.htm.In that i write a form submitting and validations.But validations are not worked in that .htm file. I used the same code in my...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.