string

Split string into array using multi-character delimiter

自作多情 提交于 2021-02-16 20:26:11
问题 I need to split a string into an array. My problem is that the delimiter is a 3 character one: _-_ For example: db2-111_-_oracle12cR1RAC_-_mariadb101 I'd need to create the following array: db2-111 oracle12cR1RAC mariadb101 Similar questions followed this approach: str="db2-111_-_oracle12cR1RAC_-_mariadb101" arr=(${str//_-_/ }) echo ${arr[@]} Even if the array is created, it has been split uncorrectly: db2 111 oracle12cR1RAC mariadb101 It seems that the "-" character in the first item causes

Split string into a list on whitespace, excluding single spaces when the next character is not a dash

♀尐吖头ヾ 提交于 2021-02-16 20:18:19
问题 I'm scraping a website that has a table of satellite values (https://planet4589.org/space/gcat/data/cat/satcat.html). Because every entry is only separated by whitespace, I need a way to split the string of data entries into an array. However, the .split() function does not suit my needs, because some of the data entries have spaces (e.g. Able 3 ), I can't just split everything separated by whitespace. It get's trickier, however. In some cases where no data is available, a dash ("-") is used.

pandas: Dataframe.replace() with regex

和自甴很熟 提交于 2021-02-16 19:12:21
问题 I have a table which looks like this: df_raw = pd.DataFrame(dict(A = pd.Series(['1.00','-1']), B = pd.Series(['1.0','-45.00','-']))) A B 0 1.00 1.0 1 -1 -45.00 2 NaN - I would like to replace '-' to '0.00' using dataframe.replace() but it struggles because of the negative values, '-1', '-45.00'. How can I ignore the negative values and replace only '-' to '0.00' ? my code: df_raw = df_raw.replace(['-','\*'], ['0.00','0.00'], regex=True).astype(np.float64) error code: ValueError: invalid

pandas: Dataframe.replace() with regex

心已入冬 提交于 2021-02-16 19:10:33
问题 I have a table which looks like this: df_raw = pd.DataFrame(dict(A = pd.Series(['1.00','-1']), B = pd.Series(['1.0','-45.00','-']))) A B 0 1.00 1.0 1 -1 -45.00 2 NaN - I would like to replace '-' to '0.00' using dataframe.replace() but it struggles because of the negative values, '-1', '-45.00'. How can I ignore the negative values and replace only '-' to '0.00' ? my code: df_raw = df_raw.replace(['-','\*'], ['0.00','0.00'], regex=True).astype(np.float64) error code: ValueError: invalid

pandas: Dataframe.replace() with regex

房东的猫 提交于 2021-02-16 19:09:48
问题 I have a table which looks like this: df_raw = pd.DataFrame(dict(A = pd.Series(['1.00','-1']), B = pd.Series(['1.0','-45.00','-']))) A B 0 1.00 1.0 1 -1 -45.00 2 NaN - I would like to replace '-' to '0.00' using dataframe.replace() but it struggles because of the negative values, '-1', '-45.00'. How can I ignore the negative values and replace only '-' to '0.00' ? my code: df_raw = df_raw.replace(['-','\*'], ['0.00','0.00'], regex=True).astype(np.float64) error code: ValueError: invalid

How to use calloc() in C?

余生颓废 提交于 2021-02-16 19:02:50
问题 Shouldn't I get an error if my string goes over 9 characters long in this program? // CString.c // 2.22.11 #include <stdio.h> #include <stdlib.h> #include <string.h> main() { char *aString = calloc(10, sizeof(char)); if (aString == NULL) { return 1; } printf("PLEASE ENTER A WORD: "); scanf("%s", aString); printf("YOU TYPED IN: %s\n", aString); //printf("STRING LENGTH: %i\n", strlen(aString)); } Thanks blargman 回答1: You don't get a compiler error because the syntax is correct. What is

Removing multiple blanks using putchar and getchar in C

こ雲淡風輕ζ 提交于 2021-02-16 18:24:27
问题 Problem: Write a program that receives textual input using getchar() and outputs the string, having removed multiples blanks. Here's how I wrote the pseudo-code: While each input character is received before reaching EOF, do the following: 1) if character is non-blank, print it out 2) otherwise: a. print out the blank b. do nothing untill the next non-blank character 3) if a non-blank character is reached, go back to 1) I tried to implement the algorithm as such: #include <stdio.h> /*

C++ exception return type why char*

我的梦境 提交于 2021-02-16 17:57:22
问题 Could someone explain why self-written C++ exception, that inherit from exception return a char * and not a string? class myexception: public exception { virtual const char* what() const throw() { return "My exception happened"; } } myex; Source : http://www.cplusplus.com/doc/tutorial/exceptions/ 回答1: Since std::exception was designed as a base class for all exceptions, the interface is written in such a way that specializations do not require code that may throw. They may use it, but they do

LINQ contains one match from array of strings

北慕城南 提交于 2021-02-16 16:01:48
问题 Having trouble getting this to work: /// <summary> /// Retrieve search suggestions from previous searches /// </summary> public static string[] getSearchSuggestions(int SectionID, string Query) { string[] Suggestions; string[] Words = Query.Split(' '); using (MainContext db = new MainContext()) { Suggestions = (from c in db.tblSearches where c.SectionID == SectionID && Words.Any(w => c.Term.Contains(w)) select c.Term).ToArray(); } return Suggestions; } I get: System.NotSupportedException:

LINQ contains one match from array of strings

核能气质少年 提交于 2021-02-16 16:01:41
问题 Having trouble getting this to work: /// <summary> /// Retrieve search suggestions from previous searches /// </summary> public static string[] getSearchSuggestions(int SectionID, string Query) { string[] Suggestions; string[] Words = Query.Split(' '); using (MainContext db = new MainContext()) { Suggestions = (from c in db.tblSearches where c.SectionID == SectionID && Words.Any(w => c.Term.Contains(w)) select c.Term).ToArray(); } return Suggestions; } I get: System.NotSupportedException: