read text files

icon picker
file names

assignment: read text file, use substring
this is a assignment program
read a list of values from a text file
use length function to calculate the size of a file name
use substring to select some letters from a text value

program requirement
read the file values into an array
display all the array values in full as well as the length of each string
display the end section of all array values
display the start of some array values which match a target value

substring: start/end, using if()

sometime substring is used to select characters at the end of the string
the position at the end of a string depends on how long the string is, so the length function helps
select characters at start / end of a string: use the length of the string to help select the last character
start always begins at position 0, the length of the first string is 9, the second 12 and the third 11
end is always at the position given by the length of the string, use this for the second parameter
count back from the end for a substring at the end of a string to calculate the first parameter, using (-2) gives the last two characters

substring can be used with an if condition and the .equals function
Use substring with an if() conditional construct to decide option based on substring value

constructs used


file handling
open file
read file
close file

data structure
• string array
control structure
fixed loop using index
if conditional
substring function
startswith function

Input requirements


Sample data from file, file names including the file type extension

Output requirements


Display full file list with name and extension
file extensions only for all files
png files, display without extension

design: main steps

code: repl program

Loading…


Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.