184,993 questions
-10
votes
1
answer
78
views
What are the different ways to reverse a string in Python? [duplicate]
I am learning Python and want to reverse a string.
Example:
Input: hello
Output: olleh
I know slicing works (s[::-1]) but I want to know if there are other Pythonic or recommended ways to do it. Is ...
1
vote
1
answer
53
views
Change micropython unicode notation from \xb0 to \u00b0 in string
I am using Micropython on the ESP32.
I have the following string, which includes the unicode character \xb0.
a = 'abc\xb0def'
First, I will need to change the notation to the \U00XX form, second I ...
-4
votes
0
answers
58
views
Why does Python treat two identical string literals differently when modified inside a loop? [duplicate]
was experimenting with string handling and noticed something confusing.
In the following code, two identical string literals behave differently depending on where they are used:
s1 = "harsh"
...
0
votes
1
answer
100
views
How to create 2 new columns in R (date difference + convert Seasons to minutes)? [duplicate]
I am new to R and trying to create two new variables from my dataset.
My data frame is called netflix and it contains these relevant columns:
date_added and duration
Example values:
date_added: "...
Best practices
2
votes
8
replies
186
views
What is the optimal way to define a global constant string in C++20?
I need to define several constant strings that will be used across an entire C++20 project.
I am considering the following options :
constexpr char[] str1 = "foo";
constexpr std::string str2 ...
3
votes
2
answers
83
views
How do these 2 string buffers interact? Why does the internal logger buffer append to the buffer i dynamically allocate in main
So, for context, I have started writing a small HTTP-Server for learning purposes.
Currently, I have 2 modules: server and logger. The server module uses the logger I wrote internally for logging ...
Advice
0
votes
2
replies
60
views
slicing html text based on length of plain text
I have a problem where I need to cut off text based on a max length. But the inputted string could be html a la <p>hello</p>. the html tags do not count towards the max length.
for example ...
2
votes
1
answer
56
views
backslash count in raw string interpolation in scala
I am using Scala 3.3.7.
When I do
val str1 = raw"\\\" // compile error: unclosed string literal
It is considering the \" as a single character.
But when I do
val str1 = raw"\\\\&...
Best practices
0
votes
2
replies
118
views
What is standard practice for handling VBA fixed-length string data in binary files?
I'm quite frustrated trying to write to a binary file in Excel VBA. The issue is with fixed-length string data in a Type structure. (Note that my binary file requirements are that fixed-length string ...
1
vote
1
answer
109
views
Pandas converts Excel strings like ‘2004E205’ to scientific notation — how to prevent this
How can I handle string values that contain patterns like xxxE205 (e.g., 2004E205), which are used as unique codes in my company? I explicitly read the column as a string in pandas, but values ...
-1
votes
0
answers
37
views
How to handle non-numeric input when using scanner.nextInt() in Java [duplicate]
I’m learning Java and testing basic input handling.
I wrote the following simple program:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner ...
2
votes
3
answers
238
views
Why is a custom specialization of std::hash<std::string> allowed?
I implemented std::hash<std::string> in the usual way, by specializing the std::hash template. But then I realized that these should already be provided by the <string> header (https://www....
-3
votes
1
answer
182
views
How to create a dictionary where the keys are the alphabet (A-Z), and values are a letter from a string in Python?
I have to create a dictionary, where the keys are letters of the alphabet, and the values are the indexed letters of a given string.
Example:
Given the string "BDFHJLCPRTXVZNYEIWGAKMUSQO" ...
Advice
0
votes
3
replies
66
views
String manipulation: extract words under brackets
I'm not yet very familiar with the patterns in Lua's string.gsub function.
If I have a string like this:
Fishing Lure(+100 Fishing Skill)(1 hour)
and I want extract only the string "1 hour"...
0
votes
0
answers
56
views
Issue With Jsoup Document Selector
I'm using java spring boot and jsoup and recently I upgraded jsoup version to 1.21.1.
My code creates search query and searches for it in the document
Elements targetElements = document.select(...