473,474 Members | 1,438 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 26563
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: 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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.