Skip to main content

New answers tagged

0 votes

Join strings with different last delimiter

Yes, this is a common requirement (often called joining with a different last delimiter). The standard Collectors.joining(", ") does not support this directly, but you can handle it cleanly ...
Amresh Yadav's user avatar
0 votes

Join strings with different last delimiter

As noted by @NarutoUzumaki in this answer, JDK 22 provides ListFormat which does this for lists with and/or in a locale-sensitive way (with or without the oxford comma). In JDK SE 22 we have a ...
Joshua Goldberg's user avatar
0 votes

Find row with longest string in R

Here is a dplyr option: library(dplyr) DF %>% filter(nchar(V1) == max(nchar(V1)))
Quinten's user avatar
  • 43.1k
1 vote

How can I check if 2 columns have similar text in pyspark?

You can use probabilistic record linkage to find similarities between words, which will help link table columns. Also, if you are using Databricks, you can use Databricks ARC. This will find and link ...
Nikhil M.'s user avatar
2 votes

How can I generate random strings consisting of eight hex digits?

There's also the String::Random, which provides various ways to create strings passed on patterns, structure, or something else you might define: use String::Random; use v5.10; use String::Random qw(...
brian d foy's user avatar
1 vote

How can I generate random strings consisting of eight hex digits?

my $rand_hex = join '', map {[0..9,A..F]->[rand 16]} 1..8; This will generate a string, not just a sequential print (as the method shown above). I'm not a grand master in Perl but for me this is ...
Reflective's user avatar
  • 3,947
0 votes

How to convert CharSequence to String?

If you wish to tolerate null values for your CharSequence object, see the excellent Answer by Minhas Kamal. Not tolerating null If you do not want to tolerate null values, then use the Objects utility ...
Basil Bourque's user avatar
1 vote

How can I check if 2 columns have similar text in pyspark?

Encode both category columns with a semantic model like a BERT model (There are many on hugging face) then calculate the cosine similarity of the encoded columns. Here is a medium article explaining ...
Progress's user avatar
  • 317
0 votes

How can I slice each element of a numpy array of strings?

There are a few ways. Convert to characters (if all strings have the same length). arr = np.array(['hello', 'world', 'numpy']) chars = arr.astype('U6').view('U1').reshape(len(arr), 6) chars[:, 1] ...
Konchog's user avatar
  • 2,248
0 votes

How to implode a vector of strings into a string (the elegant way)

For a solution working on all kinds of containers, not just std::vector, you can use following template function making use of a std::ostringstream, which is more efficient in terms of memory ...
Jens's user avatar
  • 478
0 votes

Is it safe to use `strstr` to search for multibyte UTF-8 characters in a string?

Please check the UTF-8 encoding way in wikipedia. strstr(haystack, needle): For the first byte of a character in needle, there are only two cases for the leading bits: starts with 0 at first bit ...
Ben Song's user avatar
0 votes

How to get the all text from a cell before last number?

Maybe just this which I think will grab as many characters as it can, as long as they are followed by a digit? =REGEXEXTRACT(A1,".*\d")
Tom Sharpe's user avatar
  • 35.4k
1 vote

Check if a `std::string` uses small string optimization (SSO)

Tony is right that you cannot get the answer by converting the pointers to integers, even should the implementation allow that, as the the ordering of the pointees can be completely unrelated to the ...
Deduplicator's user avatar
0 votes

How do I apply a string function to a table column?

Some how late ;), but it could help new users What I understand is that, given an array, OP wanted to apply the statements on each element of the array. Which can be achieved, from PHP5.4 on, with : $...
Best practices
0 votes
0 replies
0 views

Unescape string to get special character from user input

There may be a simpler way, but this should work: >>> from ast import literal_eval >>> separator = '\\n' >>> separator = literal_eval(f'"{separator}"') >>>...
Booboo's user avatar
  • 46.2k
Best practices
2 votes
0 replies
0 views

Unescape string to get special character from user input

primitive method: if separator == "\\n": separator = "\n" :) If you may have other strings with \\ then you may use encode()/decode() with raw_unicode_escape/unicode_escape This ...
furas's user avatar
  • 149k
1 vote

Swift string truncates / does not hold enough content

It was a javascript error. On this line: obj.fromname = json['cargo']['loads'][0]['consignorName]; There was a quote missing. Also.... NSLog truncates output. Print doesn't - good to know..
osku's user avatar
  • 341
Advice
0 votes
0 replies
0 views

Searching for strings in multiple text files and outputting matched lines to a CSV

Maybe first use print() to see what code is executed and what you have in variables. Sometimes it is called "print debuging" and it can help to understand what can be the problem. First ...
furas's user avatar
  • 149k
0 votes

UTF8 vs. UTF16 vs. char* vs. what? Someone explain this mess to me!

I need this answer for both Unix and Windows). Unix and Windows took totally different approaches to adopting Unicode. Windows NT adopted the original 16-bit Unicode as its main internal format, and ...
plugwash's user avatar
  • 11.3k
0 votes

How to split a string in half, into two variables, in one statement?

how about this: class String def split_at(i) return [self[0...i], self[i..-1]] end def split_by(r) return [self] unless m = r.match(self) return [ m.pre_match, m[0], m.post_match ] ...
Toni Schilling's user avatar
0 votes

C# string Split without array generation

Zero allocation method for .NET 9+: String largeString = GetVeryLargeString(); ReadOnlySpan<char> stringView = largeString.AsSpan(); foreach (Range range in stringView.Split(Environment.NewLine))...
dimaaan's user avatar
  • 940
2 votes

Check if a string contains an uppercase letter, in Java

tl;dr Use modern Java. input.codePoints().anyMatch( Character :: isUpperCase ) IntStream of code point numbers The char type has been essentially broken since Java 2, and legacy since Java 5. As a 16-...
Basil Bourque's user avatar
0 votes

Java Method to find uppercase letters and numbers in a String

tl;dr Use code point integer numbers when working with individual characters. Avoid char type. "Hello 42" .codePoints() // Generate an ` IntStream ` of code points. .filter ...
Basil Bourque's user avatar

Top 50 recent answers are included