indexOf allows you to find a particular character or substring within the string and substring allows you to extract a piece from it if you know the start and end points.
So if the data is at fixed positions you can extract the data directly using substring. If it is at variable positions but you know a character in between each part (e.g. space) then you first use indexOf to find the positions followed by substring to get the pieces.