---
id: post/nataliekarolak-com/4184
type: post
title: Using Substring to replace CopyStr
summary: BC 27.1 and later resolve a runtime error when using the Substring method with length parameters that exceed string boundaries, making it safe to replace CopyStr with Substring for improved code readability.
tier: community
language: en
tags:
  - substring method
  - copystr
  - string handling
  - code readability
  - runtime errors
  - platform fixes
system: development
review:
  state: reviewed
  by: opus
  at: "2026-10-25T18:23:14.335Z"
  flags: []
generated:
  at: "2026-10-25T18:17:26.277Z"
  pipeline: 0.2.0
  prompts:
    extract-post: 1
  input_hash: 09da69ea8de8284e501c7213396e427f6acb4ff8803f8875dd05afb7c637a83f
evidence:
  - kind: blog
    url: https://nataliekarolak.wordpress.com/2026/04/23/using-substring-to-replace-copystr/
    title: Using Substring to replace CopyStr
    date: "2026-04-23"
    commit: null
    t: null
    quote: null
  - kind: blog
    url: https://nataliekarolak.wordpress.com/2026/04/23/using-substring-to-replace-copystr/
    title: Using Substring to replace CopyStr
    date: "2026-04-23"
    commit: null
    t: null
    quote: With BC 27.1 and beyond, you can safely replace CopyStr with Substring to improve code readability!
  - kind: blog
    url: https://nataliekarolak.wordpress.com/2026/04/23/using-substring-to-replace-copystr/
    title: Using Substring to replace CopyStr
    date: "2026-04-23"
    commit: null
    t: null
    quote: Index and length must refer to a location within the string.
  - kind: blog
    url: https://nataliekarolak.wordpress.com/2026/04/23/using-substring-to-replace-copystr/
    title: Using Substring to replace CopyStr
    date: "2026-04-23"
    commit: null
    t: null
    quote: BC 27.1 is the first application version having the fix in any case.
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
post_id: "4184"
source_id: nataliekarolak-com
source_name: The BC Docs Librarian
url: https://nataliekarolak.wordpress.com/2026/04/23/using-substring-to-replace-copystr/
published_at: "2026-04-23T13:27:43.000Z"
author: Natalie Karolak
full_text: false
words: 268
quotes:
  - text: With BC 27.1 and beyond, you can safely replace CopyStr with Substring to improve code readability!
    why_it_matters: This signals when developers can confidently migrate to the newer, more readable method.
  - text: Index and length must refer to a location within the string.
    why_it_matters: This is the exact error message developers encountered when using Substring with invalid length parameters in earlier versions.
  - text: BC 27.1 is the first application version having the fix in any case.
    why_it_matters: This clarifies the minimum version requirement for guaranteed Substring support across all deployment types.
code_objects_mentioned: []
systems:
  - development
versions_mentioned:
  - "27.1"
  - "27.0"
  - "25.0"
cautions:
  - kind: breaking
    quote: When we executed that code line in – let's say – Business Central 25.0, then a runtime error was thrown.
    objects: []
    events: []
    versions:
      - "25.0"
  - kind: gotcha
    quote: BC 27.0 online would include the fix, but BC 27.0 on-premises does not.
    objects: []
    events: []
    versions:
      - "27.0"
preview:
  embeddable: true
  frame_url: https://nataliekarolak.wordpress.com/2026/04/23/using-substring-to-replace-copystr/embed/
  image: https://nataliekarolak.wordpress.com/wp-content/uploads/2026/04/substring-1.jpg
  image_alt: null
  image_w: 736
  image_h: 491
  site_name: The BC Docs Librarian
  favicon: https://nataliekarolak.wordpress.com/wp-content/uploads/2022/11/cropped-logo-216x216-1.png?w=32
  probed_at: "2026-10-25T18:21:51.239Z"
---

# Using Substring to replace CopyStr

[Read the post](https://nataliekarolak.wordpress.com/2026/04/23/using-substring-to-replace-copystr/) · The BC Docs Librarian (Natalie Karolak, MVP) · 2026-04-23 · 268 words · tier community · reviewed (checked by Opus)

> BC 27.1 and later resolve a runtime error when using the Substring method with length parameters that exceed string boundaries, making it safe to replace CopyStr with Substring for improved code readability.

## Key points

- Substring threw a runtime error in older versions such as BC 25.0 when the requested length went past the end of the string; a later BC 27.0 platform build fixed this
- BC 27.0 online has the fix but BC 27.0 on-premises does not; BC 27.1 is the first application version that has it in all cases
- CopyStr is still supported with no plans to obsolete it, so both methods can be used
- To use Substring safely, set the application property in app.json to 27.1.0.0 or higher; the runtime property and AL Language version do not matter

## Quotes

- "With BC 27.1 and beyond, you can safely replace CopyStr with Substring to improve code readability!" (This signals when developers can confidently migrate to the newer, more readable method.)
- "Index and length must refer to a location within the string." (This is the exact error message developers encountered when using Substring with invalid length parameters in earlier versions.)
- "BC 27.1 is the first application version having the fix in any case." (This clarifies the minimum version requirement for guaranteed Substring support across all deployment types.)

## Heads up

- breaking: "When we executed that code line in – let's say – Business Central 25.0, then a runtime error was thrown." (about version 25.0)
- gotcha: "BC 27.0 online would include the fix, but BC 27.0 on-premises does not." (about version 27.0)

## Context

- Features: Substring method, CopyStr method
- Versions: 27.1, 27.0, 25.0

Source: The BC Docs Librarian, community blog. Summary, key points and quotes are derived (CONTENT-NOTICE.md); read the original for the full text.
