I am trying to cut the string into 6 fields with maximum length of 30 per field. Total length of the string is 173. I have created a code as below;
(
(("" + dr["MESSAGE"]).ToString().Trim().Length<30 &&
("" + dr["MESSAGE"]) != "")?(("" + dr["MESSAGE"]) + "|||||") :
(("" + dr["MESSAGE"]).ToString().Trim().Length>150 &&
("" + dr["MESSAGE"]).ToString().Trim().Length<181)?
(("" + dr["MESSAGE"]).Trim().PadRight(180,' ').Substring(0,30).Trim() + "|" +
("" + dr["MESSAGE"]).Trim().PadRight(180,' ').Substring(31,60).Trim() + "|" +
("" + dr["MESSAGE"]).Trim().PadRight(180,' ').Substring(61,90).Trim() + "|" +
("" + dr["MESSAGE"]).Trim().PadRight(180,' ').Substring(91,120).Trim() + "|" +
("" + dr["MESSAGE"]).Trim().PadRight(180,' ').Substring(121,150).Trim() + "|" +
("" + dr["MESSAGE"]).Trim().PadRight(180,' ').Substring(151,180).Trim()) : "" + "|||||")
The code itself generates an output file but without the data. All I get is the header and the footer with the error "Index and length must refer to a location within the string" indicated at the bottom of the output file.
Would appreciate your help in resolving my issue.