0
string s = @"This is the first line.
             and this is the second line without escapes
             and another one joins the fuss";

we do this in C#, put an @ for assigning literal text to strings without any escape characters.

Now I gotta do this in Java & I'm new to Java. Could anyone tell me how to do the same in Java.

p.s I know this is a bad question but bear with me... from the following you will know why this is so important for me

INSERT INTO `timetable` (`ID`, `teacherID`, `courseID`, `dayOfWeek`, `startTime`, `endTime`, `Block`, `RoomNo`, `isSynchronized`) VALUES
(1, 1, 'CS105', 1, '08:00:00', '09:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(2, 1, 'CS105', 1, '09:00:00', '10:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(3, 1, 'CS105', 1, '10:00:00', '11:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(4, 1, 'CS105', 1, '11:00:00', '12:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(5, 1, 'CS105', 1, '12:00:00', '13:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(6, 1, 'CS105', 1, '13:00:00', '14:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(7, 1, 'CS105', 1, '14:00:00', '15:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(8, 1, 'CS105', 1, '15:00:00', '16:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(9, 1, 'CS105', 1, '16:00:00', '17:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(10, 1, 'CS105', 2, '08:00:00', '09:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(11, 1, 'CS105', 2, '09:00:00', '10:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(12, 1, 'CS105', 2, '10:00:00', '11:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(13, 1, 'CS105', 2, '11:00:00', '12:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(14, 1, 'CS105', 2, '12:00:00', '13:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(15, 1, 'CS105', 2, '13:00:00', '14:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(16, 1, 'CS105', 2, '14:00:00', '15:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(17, 1, 'CS105', 2, '15:00:00', '16:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(18, 1, 'CS105', 2, '16:00:00', '17:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(19, 1, 'CS105', 3, '08:00:00', '09:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(20, 1, 'CS105', 3, '09:00:00', '10:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(21, 1, 'CS105', 3, '10:00:00', '11:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(22, 1, 'CS105', 3, '11:00:00', '12:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(23, 1, 'CS105', 3, '12:00:00', '13:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(24, 1, 'CS105', 3, '13:00:00', '14:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(25, 1, 'CS105', 3, '14:00:00', '15:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(26, 1, 'CS105', 3, '15:00:00', '16:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(27, 1, 'CS105', 3, '16:00:00', '17:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(28, 1, 'CS105', 4, '08:00:00', '09:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(29, 1, 'CS105', 4, '09:00:00', '10:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(30, 1, 'CS105', 4, '10:00:00', '11:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(31, 1, 'CS105', 4, '11:00:00', '12:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(32, 1, 'CS105', 4, '12:00:00', '13:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(33, 1, 'CS105', 4, '13:00:00', '14:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(34, 1, 'CS105', 4, '14:00:00', '15:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(35, 1, 'CS105', 4, '15:00:00', '16:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(36, 1, 'CS105', 4, '16:00:00', '17:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(37, 1, 'CS105', 5, '08:00:00', '09:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(38, 1, 'CS105', 5, '09:00:00', '10:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(39, 1, 'CS105', 5, '10:00:00', '11:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(40, 1, 'CS105', 5, '11:00:00', '12:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(41, 1, 'CS105', 5, '12:00:00', '13:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(42, 1, 'CS105', 5, '13:00:00', '14:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(43, 1, 'CS105', 5, '14:00:00', '15:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(44, 1, 'CS105', 5, '15:00:00', '16:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(45, 1, 'CS105', 5, '16:00:00', '17:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(46, 1, 'CS105', 6, '08:00:00', '09:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(47, 1, 'CS105', 6, '09:00:00', '10:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(48, 1, 'CS105', 6, '10:00:00', '11:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(49, 1, 'CS105', 6, '11:00:00', '12:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(50, 1, 'CS105', 6, '12:00:00', '13:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(51, 1, 'CS105', 6, '13:00:00', '14:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(52, 1, 'CS105', 6, '14:00:00', '15:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(53, 1, 'CS105', 6, '15:00:00', '16:00:00', 'Allama Iqbal Block', 'LH-786', 0),
(54, 1, 'CS105', 6, '16:00:00', '17:00:00', 'Allama Iqbal Block', 'LH-786', 0);

and there is a lot more of these I can't spend all day converting these to one-liners.

Moon
  • 19,518
  • 56
  • 138
  • 200
  • Have you tried reading that from a file and then using StringBuilder or StringBuffer to create a String? – TeTeT May 29 '14 at 08:03
  • 1
    Write text into a file; load file at runtime... – Marc Gravell May 29 '14 at 08:04
  • So you want to add a newline character at the end of every line – EdmDroid May 29 '14 at 08:04
  • no. I wanna avoid manually removing "new line character" from every-line, in order to make this text able to be assignable to a string. That's it. The thing is I have a lot of these and can't waste my time on removing these "new line characters" from everywhere, so you see how convenient the @ of C# is – Moon May 29 '14 at 08:08
  • @MarcGravell and spend more time writing code for file reading which I have not learned yet as I am new to Java and worse am working on Android... – Moon May 29 '14 at 08:09
  • don't think so... there's gotta be a better way – Moon May 29 '14 at 08:09
  • May this answer help to you if you use Eclipse: http://stackoverflow.com/a/7716231/1803777 Also you may check other answers at the link. – Ulugbek Umirov May 29 '14 at 08:10
  • 1
    @JunaidSaeed You can't escape like you can in C#. If you use IntelliJ (and presumably Android Studio) if you copy/paste the above into an empty string `""`, the IDE will automatically add the `\n` for you. Marc's suggestion is the correct approach, these are commonly packaged as .sql files – CodingIntrigue May 29 '14 at 08:10
  • Note that in C# you would probably not copy/paste 40 lines of very similar text - you'll use `for` and generate all values using `string.Format` and join them with `StringBuilder`... I'd hope Java have `for` too :) – Alexei Levenkov May 29 '14 at 08:14

1 Answers1

0

There are no string literals in Java.

Moon
  • 19,518
  • 56
  • 138
  • 200