string

C: strtok delivers segmentation fault

跟風遠走 提交于 2021-02-17 06:38:06
问题 I am trying to read a file line by line, and tokenize each line, which have strings separated by spaces and tabs. However, when I run my program, I get the a Segmentation Fault error when I try to print the token. I don't understand why this is happening, as I am using a buffer as the string to tokenize and checking if the token is null. Below is my code: #include <stdio.h> #include <stdlib.h> #define MAX_LINE_LENGTH 70 int main(void) { FILE * testFile; char buf[MAX_LINE_LENGTH]; testFile =

Dynamic properties name in PHP

偶尔善良 提交于 2021-02-17 06:19:11
问题 There is an object in PHP named $item , and in this object I have properties of title , title_cn, title_tw And I would like to create an function that auto generate the properties based on the language, so I coding like this: <?= $item->title . set_lang(); ?> And the function: function set_lang() { $CI =& get_instance(); $lang = $CI->session->userdata('site_lang'); if ($lang == "english") { return ""; } else if ($lang == "zh_tw") { return "_tw"; } else if ($lang == "zh_cn") { return "_cn"; }

write Python string object to file

北城以北 提交于 2021-02-17 06:15:08
问题 I have this block of code that reliably creates a string object. I need to write that object to a file. I can print the contents of 'data' but I can't figure out how to write it to a file as output. Also why does "with open" automatically close a_string? with open (template_file, "r") as a_string: data=a_string.read().replace('{SERVER_NAME}', server_name).replace('{BRAND}', brand).replace('{CONTENT_PATH}', content_path).replace('{DAMPATH}', dampath).replace('{ENV}', env).replace('{CACHE

make upper case and replace space in column dataframe

走远了吗. 提交于 2021-02-17 06:02:51
问题 for a specific column of a pandas dataframe I would like to make the elements all uppercase and replace the spaces import pandas as pd df = pd.DataFrame(data=[['AA 123',00],[99,10],['bb 12',10]],columns=['A','B'],index=[0,1,2]) # find elements 'A' that are string temp1 = [isinstance(s, str) for s in df['A'].values] # Make upper case and replace any space temp2 = df['A'][temp1].str.upper() temp2 = temp2.str.replace(r'\s', '') # replace in dataframe df['A'].loc[temp2.index] = temp2.values I get

How to iterate over character strings with numbers, words and blancks in Fortran90?

随声附和 提交于 2021-02-17 06:00:07
问题 Description of the file: The STL file consists of solid <solid_name> facet normal n1 n2 n3 (the triangles normal vector) outerloop (one of the markers I want to read) v1 x1 y1 z1 v2 x2 y2 z2 (three vertex of the triangle/facet) v3 x3 y3 z3 endloop end facet endsolid The idea is to read the information in each line. First, I'm trying !to read the first line:solid program Leitura !use, intrinsic :: trim implicit none integer ilo, ierror, ihi, ios, iunit, num_text, len_blanck, len_word, len_text

python delete 2 character in string

北慕城南 提交于 2021-02-17 05:41:27
问题 python search character "x" next step delete this character "x" + character "x" -1 postion in string Example x="1. 520 2. 529" I am going to search in x "." and delete "." and number before "." in end I want it look like x=" 520 529" Before I created this topic I only find replace one character for one character 回答1: import re re.sub(r'(.\.)', '', a) Where a is the string you want to replace in. 来源: https://stackoverflow.com/questions/43957288/python-delete-2-character-in-string

TypeError: unsupported operand type(s) for +: 'int' and 'str' when using str(sum(list))

血红的双手。 提交于 2021-02-17 05:24:42
问题 I'm going through the Python tutorial and have no idea why my code isn't working. I know I need to tell Python to print an integer manually but I have already put str(sum(ages)) . Can anyone tell me why this is happening? ages = ['24','34','51','36','57','21','28'] print('The oldest in the group is ' + str(max(ages)) + '.') print('The youngest in the group is ' + str(min(ages)) + '.') print('The combined age of all in the list is ' + str(sum(ages)) + '.') Error: File "list2.py", line 4, in

Javascript Prototype String - accessing string value

蹲街弑〆低调 提交于 2021-02-17 05:17:33
问题 Im trying to Add a few methods to the Javascript String Object. one of the main methods im trying to add is a substring count function String.prototype.substring_count = function(delimiter){ return {THIS IS WHAT I NEED THE STRING FOR}.split(delimiter).length; } Where do you access the string in the String object? 回答1: Use this . In the documentation, it is mentioned If the method is on an object's prototype chain, this refers to the object the method was called on in this case, the string

Check whether a website provides photo or video based on a pattern in its URL

夙愿已清 提交于 2021-02-17 05:15:13
问题 I am wondering how I can figure out if a website provide photo or video by checking its URL. I investigated the website that I am interested in and found that most of the links I have are in this form: (I am not sure if I can actually name the website, so for now I just wrote it in a form of an example): http://www.example.com/abcdef where example is the main domain and abcdef is a number like 69964. The interesting pattern I found is that after entering this URL, if it actually has video the

Check whether a website provides photo or video based on a pattern in its URL

…衆ロ難τιáo~ 提交于 2021-02-17 05:15:09
问题 I am wondering how I can figure out if a website provide photo or video by checking its URL. I investigated the website that I am interested in and found that most of the links I have are in this form: (I am not sure if I can actually name the website, so for now I just wrote it in a form of an example): http://www.example.com/abcdef where example is the main domain and abcdef is a number like 69964. The interesting pattern I found is that after entering this URL, if it actually has video the