I have a string which is like
name : Rahul
surname : Chopra
school : KVMPSS
I need to read the first line , thats the name : Rahul then delete the rest. How can I do it. I am new to nodejs. Please help
Do this to get the first line of your file:
your_string = "hi\nhello\nhello\nworld";
line_1 = your_string.split(/\r?\n/)[0];
console.log(line_1)
This is not efficient for large files, but it's fine for smaller ones.
I have a dictionary which has following text:
{
"body": "Customer: \"I have a big problem. You cut off my head!\"\r\n\r\nMe: \"I'm sorry? How did I cut off your head?\"\r\n\r\n(The customer shows me an obviously self-taken picture, with the top of his head removed.)\r\n\r\nMe: \"Sir, it looks like it was taken that way.\"\r\n\r\nCustomer: \"No it wasn't! My whole head was there when I took it. I'm sure!\"\r\n\r\nMe: \"Okay, let me see your memory card...\"\r\n\r\n(The customer hands it to me, and I go in the lab and pull it up on the computer. Sure enough, he chopped his own head off in the picture.)\r\n\r\nMe: \"Sir, that is the whole image, and the top of your head isn't in it.\"\r\n\r\nCustomer: \"But it's DIGITAL, can't you fix it?\"\r\n\r\nMe: \"You can't create something from nothing.\"\r\n\r\nCustomer: \"But... but... but... I need a photo for a dating website!\"\r\n\r\nMe: \"Give me the camera and go stand over there.\"\r\n\r\nCustomer: *excited* \"Hot d***! You can be my best man!\"\r\n\r\nMe: \"A thank you card will be enough.\"\r\n\r\n(Skip ahead 9 months...)\r\n\r\nFemale customer: \"Is your name ***?\"\r\n\r\nMe: \"Yes, can I help you?\"\r\n\r\nFemale customer: \"My husband wanted you to have this.\" *hands me an envelope*\r\n\r\n(I open the envelope, and sure enough there's a thank you card with a picture of him and his wife. He actually got married and sent her in with the card!)",
"category": "Men / Women",
"id": 18189,
"title": "A Heady Proposition"
},
But I am not sure at all how to parse the text for body so that I can get a readable text from above.
I am looking for a general solution instead of parsing based on keywords like Customer and Me
The text should look as following image:
You can split by the delimiter pattern \r\n\r\n+
Using the re and pprint modules:
pprint(re.split('\r\n\r\n+',your_dict['base']))
generates:
['Customer: "I have a big problem. You cut off my head!"',
'Me: "I\'m sorry? How did I cut off your head?"',
'(The customer shows me an obviously self-taken picture, with the top of his '
'head removed.)',
'Me: "Sir, it looks like it was taken that way."',
'Customer: "No it wasn\'t! My whole head was there when I took it. I\'m '
'sure!"',
'Me: "Okay, let me see your memory card..."',
'(The customer hands it to me, and I go in the lab and pull it up on the '
'computer. Sure enough, he chopped his own head off in the picture.)',
'Me: "Sir, that is the whole image, and the top of your head isn\'t in it."',
'Customer: "But it\'s DIGITAL, can\'t you fix it?"',
'Me: "You can\'t create something from nothing."',
'Customer: "But... but... but... I need a photo for a dating website!"',
'Me: "Give me the camera and go stand over there."',
'Customer: *excited* "Hot d***! You can be my best man!"',
'Me: "A thank you card will be enough."',
'(Skip ahead 9 months...)',
'Female customer: "Is your name ***?"',
'Me: "Yes, can I help you?"',
'Female customer: "My husband wanted you to have this." *hands me an '
'envelope*',
"(I open the envelope, and sure enough there's a thank you card with a "
'picture of him and his wife. He actually got married and sent her in with '
'the card!)']
You can now print this array line by line to a PDF using the module pyPdf, with a nice font of your choice - achieving the look above +-.
You'll need to add further code to add some formatting, such as the italics above; e.g.:
Anything before a : should be bolded, and any line holding )( should be italicized.
We are trying to implement a file based student record program.We want to sort the file that contain the details of the student according to the roll number which is at the first position of every line.
the file contains the following data:
1/rahul/cs
10/manish sharma/mba
5/jhon/ms
2/ram/bba
We want to sort the file's data according to the first field i.e. roll number.
Any help shall be great
You use sorted:
dataSorted = list(sorted(f.readlines()))
If you want to sort only the first element use:
dataSorted = list(sorted(f.readlines(), lambda line: line[:line.find('/')]))
f is the file-object.
Further information: help(sorted)
I'm writing a custom function in Vim which asks the user what they would like to rename the current file to:
let b:newname = input('Rename to: ', expand('%'))
It prepopulates the input field with the filename such as ExampleFile.php. However I would like to position the cursor just before the . as more often than not, users will be renaming the file as opposed to the extension.
However, I cannot figure out a way to move the cursor. Even <Left><Left><Left> would suffice if I could get it to work
You can insert special keys in a double quote string with \<xxx>. Check the help for expr-quote. So just concatenate that to your string:
let b:newname = input('Rename to: ', expand('%') . "\<left>\<left>\<left>\<left>")
I have an output text file with millions of email addresses in them. I need an sql function to take each each email address as input and format it to add the ' and ', characters to them. So as an example:
Input is:
joe.bloggs#test.com
dan.bloggs#test.com
Expected Output:
'joe.bloggs#test.com',
'dan.bloggs#test.com',
select ''''+replace('joe.bloggs#test.com dan.bloggs#test.com', ' ', ''', ''')+''''
So to answer one of my junior devs under my login - a quick solution:
SELECT distinct(',''' + Email + '''')
FROM [Table]