string

How to find the longest substring that consists of the same char?

时光怂恿深爱的人放手 提交于 2021-02-20 02:39:08
问题 Now I try to solve task about finding length the longest substring that consists of the same char. For example, I have a string yyuuufhvksoooo , then I will get result 4 . I wrote this code, here it is: function longRepeat(line) { if (line.length > 0) { var count = 1; var max = 1; } for (let i = 0; i < line.length - 1; i++) { if (line[i] == line[i + 1]) { count++; if (count > max) max = count; } else { count = 1; } } return max; } It is work. But when I test this code with big string,

How to find the longest substring that consists of the same char?

浪尽此生 提交于 2021-02-20 02:37:57
问题 Now I try to solve task about finding length the longest substring that consists of the same char. For example, I have a string yyuuufhvksoooo , then I will get result 4 . I wrote this code, here it is: function longRepeat(line) { if (line.length > 0) { var count = 1; var max = 1; } for (let i = 0; i < line.length - 1; i++) { if (line[i] == line[i + 1]) { count++; if (count > max) max = count; } else { count = 1; } } return max; } It is work. But when I test this code with big string,

Python Regex for Words & single space

不想你离开。 提交于 2021-02-19 22:21:07
问题 I am using re.sub in order to forcibly convert a "bad" string into a "valid" string via regex. I am struggling with creating the right regex that will parse a string and "remove the bad parts". Specifically, I would like to force a string to be all alphabetical, and allow for a single space between words. Any values that disagree with this rule I would like to substitute with ''. This includes multiple spaces. Any help would be appreciated! import re list_of_strings = ["3He2l2lo Wo45rld!",

How to replace all new lines of string with `<BR>` in php?

妖精的绣舞 提交于 2021-02-19 09:13:29
问题 There are too much confusion about \n and \r. There are lot's of questions in stack about differences between \n and \r. In a nut shell My confusions/questions are: Is \r\n equal to \n\r? Is \r\n cause to two new lines? Is \r cause a new line in output? How can I replace all new lines with <BR> tag in PHP? Not all strings has \r or \n explicitly . Suppose I have a textarea and user inputs some characters including Enter of keyboard. No \r or \n is entered but new lines exist. How to remove

Official repository of Unicode character names

吃可爱长大的小学妹 提交于 2021-02-19 08:46:08
问题 There are a few ways to get the list of all Unicode characters' names: for example using Python module unicodedata, as explained in List of unicode character names, or using the website: https://unicode.org/charts/charindex.html but here it's incomplete, and you have to open and parse PDF to find the names. But what is the official source / repository of all Unicode character names? (such that if a new character is added, the list is updated, so I'm looking for the initial source for these

String to multidimensional/recursive array in PHP

女生的网名这么多〃 提交于 2021-02-19 08:25:06
问题 I have a problem with creating a recursive array with PHP. I need to format this string to a multidimensional array with the dot-separated elements indicating multiple levels of array keys. $str = "code.engine,max_int.4,user.pre.3,user.data.4"; The output for this example would be: $str = array( "code" => "engine", "max_int" => 4, "user" => array( "pre" => 3, "data" => 4 ) ); I will start with an explode function, but I don't know how to sort it from there, or how to finish the foreach. 回答1:

Removing invisible characters from the end of a Java String

冷暖自知 提交于 2021-02-19 08:02:11
问题 how can i find the last visible character in a Java String? I'd like to remove all line breaks and other invisible characters from a Java String Kind Regards, Tord 回答1: You can use the trim() method of the String class for removing trailing (and leading) white space and line breaks: String trimmed = original.trim(); 回答2: string_variable.replaceAll("\\p{C}", "?"); This will replace all non-printable characters. Where p{C} selects the invisible control characters and unused code points. 来源:

Removing invisible characters from the end of a Java String

☆樱花仙子☆ 提交于 2021-02-19 08:02:02
问题 how can i find the last visible character in a Java String? I'd like to remove all line breaks and other invisible characters from a Java String Kind Regards, Tord 回答1: You can use the trim() method of the String class for removing trailing (and leading) white space and line breaks: String trimmed = original.trim(); 回答2: string_variable.replaceAll("\\p{C}", "?"); This will replace all non-printable characters. Where p{C} selects the invisible control characters and unused code points. 来源:

php foreach counting new lines (\n)

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-19 07:41:34
问题 If I have a piece of code that works like this: $i = 0; $names = explode(",", $userInput); foreach($names as $name) { $i++; } It works perfectly, provided the user has placed a comma after each name entered into the html textarea this comes from. But I want to make it more user friendly and change it so that each name can be entered on a new line and it'll count how many lines the user has entered to determine the number of names entered into the field. So I tried: $i = 0; $names = explode("

How to split a string into a map, grouping values by duplicate keys using streams?

北城余情 提交于 2021-02-19 07:24:27
问题 I want to convert the following String flString="view1:filedname11,view1:filedname12,view2:fieldname21"; to a Map<String,Set<String>> to get the key/value as below: view1=[filedname11,filedname12] view2=[fieldname21] I want to use Java 8 streams. I tried Arrays.stream(tokens) .map(a -> a.split(":")) .collect(Collectors.groupingBy( a -> a[0], Collectors.toList())); However the keys are also getting added to the value list. 回答1: You should use a Collectors::mapping to map the array to an