Paip. Metadata-driven transformations-read file lines to a list idea uapi java PHP python summary

Source: Internet
Author: User
Paip. Metadata-driven transformations-read file lines to a list idea uapi java PHP python summary

#两个思路
1. The idea is as follows: Use File_get_contents () to get the contents of the TXT file, and then convert the obtained string into an array by explode (). Get array length You can use the count () function
2. Using the Read API by line

In the regular expression, there is a \ n is the meaning of newline, and a \ r is carriage return (that is, this led to the idiot Chinese translation "return") meaning. When working with a string or console output, it can be wrapped in any line.

Author Old Wow's paw Attilax Ayron, email:1466519819@qq.com
Reprint please indicate source: Http://blog.csdn.net/attilax

#---UAPI file2list ()

#-----Python's problem is also to replace the line break with the ENTER key:
#todox read file lines to list (not arr, arr are tech word, but List was life word)
def file2list (file):
Rplc_list = [];

For line in open (F, encoding= "Utf-8"):
if (len (line)) ==0):
Break
#endif
#print (line)
Line=trim (line)
Line=line.replace ("\ n", ""); Line=line.replace ("\ R", "" ")
Rplc_list.append (line)
#end for
Return rplc_list

#------Java
#-------PHP

$file = ' 2010-12-15.txt ';
$content = file_get_contents ($file);
Echo $content;

$array = Explode ("\ r \ n", $content);
Print_r ($array);

for ($i =0; $i 〈count ($array); $i + +)
{
echo $array [$i]. ' 〈br/〉 ';
}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.