---
title: "Splitta sträng, c#"
type: "forum-thread"
url: "https://www.webforum.nu/amne/dotnet/107270-splitta-sträng-c"
topic: ".NET"
topic_url: "https://www.webforum.nu/amne/dotnet"
author: "erka"
published: "2004-07-13T18:32:26.000Z"
updated: "2004-07-13T20:44:21.000Z"
replies: 3
views: 322
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/dotnet/107270-splitta-sträng-c"
---

# Splitta sträng, c#

## #1 — erka, 2004-07-13T18:32Z

Hej!

Jag har en sträng som jag inte vet längde på, det enda jag vet är att om den är över 8000 tecken, ska jag splitta upp den i två strängar. Men jag kan inte lyckas få det att fungera. Vad är fel i detta

```
string tmpContent = "";
string tmpContent2 = "";

if (this.ContentText.Length > 8000)
{
int tmpLenght = this.ContentText.Lenght;
tmpContent = this.ContentText.Substring(0,7999);
tmpContent2 = this.ContentText.Substring(8000,tmpLenght);
}
else
{
tmpContent = this.ContentText;
}
```

får felmeddelandet
System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. Parameter name: length
tacksam

Permalänk: https://www.webforum.nu/p/107270

## #2 — PDahlen, 2004-07-13T19:05Z

Prova
\<code\>
tmpContent2 = this.ContentText.Substring(8000,tmpLenght-8000);
\</code\>
Andra variablen i Substring är length och nu försöker du ta ut en substräng på tmpLength efter från index 8000.

Permalänk: https://www.webforum.nu/p/1385690

## #3 — erka, 2004-07-13T19:28Z

Fick det att fungera, tack för tippset

Permalänk: https://www.webforum.nu/p/1385699

## #4 — Marcus E, 2004-07-13T20:44Z

Length stavas med th.

this.ContentText.Substring(8000) fungerar lika bra för att få alla tecken efter 8000:e.

Permalänk: https://www.webforum.nu/p/1385732

---

Tråden på webben: https://www.webforum.nu/amne/dotnet/107270-splitta-sträng-c
