Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 93535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:21:34+00:00 2026-05-10T23:21:34+00:00

I have string that I want to chop to array of substrings of given

  • 0

I have string that I want to chop to array of substrings of given length n. I am not interested in remainder (if length of string cannot be divided by n without remainder)

let ChopString (myString : string) n =      let res =          seq{              for i = 0 to myString.Length / n - 1 do                 yield( String.sub myString (i*n) n )             }             |> Seq.to_array     res 

This is the best I could do. It looks ugly to me.

Is there nicer/shorter version of this, maybe without for loop?

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:21:35+00:00Added an answer on May 10, 2026 at 11:21 pm

    stringInstance.[start..end] is much more readable than String.sub. Here’s what I came up with:

         let chop (input : string) len =          seq { for start in 0 .. len .. input.Length - 1             do yield input.[start..start + len - 1] }         |> Seq.toArray 

    Or you can use:

         let chop (input : string) len =          Array.init (input.Length / len) (fun index ->             let start = index * len             input.[start..start + len - 1]) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a comma-separated string that I want to convert into an array, so
I have a string that I want as a byte array. So far I
I have a simple string that I want to read into a float without
I have a string ë́aúlt that I want to get the length of a
I have a string that I want to compare against an array of strings,
I have a string that I want passed via the linebreaks filter. {% trans
I have a string that I want to have PHP read as a piece
Hi I'm new to regexes. I have a string that I want to match
I have a string s that I want to split up so each part
I have string that displays UTF-8 encoded characters, and I want to convert it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.