devxlogo

Read specific number of chars from file

Read specific number of chars from file

Question:
I am a rookie at PowerBuilder. I use PB 5, and I can’t seem to find a function that reads a specific number of chars from a file into a string. I saw that I can read the whole file into a string, but suppose I want to read five characters from the file. How can I do it? Is it even possible?

Answer:
PowerBuilder’s file functions are stream- and line-based. Your only options are to read in a single line (terminated by ~r~n) from a file or up to a maximum of 32,767 characters to the end of the file.

With these two simple functions you can achieve most tasks. If you want the first five characters, then you can use either of the above methods to read in a chunk of data and then just use the Left function to get the characters you want.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist