New answers tagged string
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 ...
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 ...
0 votes
Find row with longest string in R
Here is a dplyr option: library(dplyr) DF %>% filter(nchar(V1) == max(nchar(V1)))
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 ...
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(...
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 ...
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 ...
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 ...
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] ...
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 ...
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 ...
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")
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 ...
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 : $...
Community wiki
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}"') >>>...
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 ...
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..
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 ...
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 ...
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 ] ...
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))...
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-...
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 ...
Top 50 recent answers are included
Related Tags
string × 184930java × 32718
python × 32573
arrays × 19113
regex × 16441
c++ × 16436
c# × 15705
c × 14279
javascript × 12383
php × 11553
list × 7100
split × 6959
replace × 6569
r × 5886
android × 5639
python-3.x × 5474
integer × 4418
char × 3914
substring × 3548
pandas × 3365
parsing × 3342
algorithm × 3284
sql × 3007
ruby × 2967
swift × 2893