Questions tagged [strings]
A "string" is a sequence of characters typically representing a unit of human-readable text. Questions on this topic deal with processing strings in programs, and how various languages and environments define and manipulate strings.
202 questions
1
vote
1
answer
193
views
Data structure for grouping strings in a collection when they share common substrings [closed]
I am looking for a data structure and an algorithm to manage a dynamic collection of strings, but grouping strings that have a substring in common. I try to describe it through an example.
@Christophe:...
-3
votes
1
answer
301
views
How to find the shortest common superstring [closed]
Problem statement:
You are given an array of strings. Each element (string) of array is of size 2. You are supposed to find the length of shortest possible string such that every element of the array ...
1
vote
3
answers
316
views
To enforce column limits on long strings? [closed]
We're trying to update our style guide (using google's guide as a starting point) and I'm currently in the middle of a debate with my colleagues about column limits. I believe we're all in agreement ...
2
votes
4
answers
350
views
Buggy auto conversion to string : In which code-smell would it fall and how should avoid one?
Consider this Java code:
int rowIndex=8;
int offset=0;
libFuncCall.populate("B"+rowIndex+offset, data);
Here I mistakenly missed the fact that, resulting argument is a String though I had ...
1
vote
3
answers
171
views
How to link many large strings in a maintainable way
I'm developing an app that will work as a troubleshooter. In this, I want to ask the customers only relevant questions instead of giving them an exhaustive list.
Every option they choose will have to ...
1
vote
2
answers
493
views
String representation in Python runtimes
Python is one of the few languages to support a string data type of code points (Unicode Scalar Values). I'm also wanting to creating a language that has this same characteristic, but I need to ...
6
votes
3
answers
2k
views
What is the benefit of caching a hash value in a string object?
I made a patch to a programming language run-time to cache the results of hashing a string in the string object, so that it is just retrieved the next time it is required.
However, I'm not convinced ...
3
votes
2
answers
409
views
What is the purpose of using strings as identifiers or flags instead of enumerated types?
I have seen in mainly high level languages, but also in lower level languages, the use of option names as strings to specify one of several fixed options, or as flags, or more generally, code using ...
-1
votes
3
answers
442
views
Is there a text distance (or string similarity) algorithm which accounts for the distance between characters?
I'm interested in finding a text distance (or string similarity) algorithm which computes a greater distance (or lower similarity) when characters are further apart.
For example, I want the distance ...
-2
votes
1
answer
676
views
C (Arduino): treat a #defined hex value as ASCII chars [closed]
This is Arduino code, but since it uses C syntax, and it's not Arduino-specific, I thought I'd ask here. I have a few values defined so:
#define PID_RPM 0x0C
Typically it's used as a hex number. But ...
-1
votes
1
answer
1k
views
Will conversion of a string to a list, and vice versa count in time complexity?
Assume that there is a question where a string needs to be passed. Some modification needs to be done on the string and then returned back.
For the programming languages like C where a string is a ...
1
vote
1
answer
176
views
Where's the interpolation in "string interpolation"?
In most contexts, the concept of "interpolation" seems to be related to estimating unknown states from known ones, like video frames or data points.
From the Wikipedia entry on interpolation:...
1
vote
2
answers
407
views
(Algorithm) Maximum Binary String After Making Changes
I am given a binary string binary consisting of only 0's or 1's. There are two allowed operations (can be re-used any number of times):
Operation 1: If the number contains the substring "00",...
4
votes
4
answers
3k
views
Is there a single word for a "non-empty" string?
Take a simple example:
string1 = ""
string2 = "foo"
string1 is empty or null, which is clear.
But what about string2? I wouldn't call it "full". "Non-empty" or ...
1
vote
3
answers
479
views
Algorithm – Number of strings containing every string of a given set a strings
I have a given set S of strings, and a length l, and I am looking for the number of strings of length l that contains every string of S. A naive approach would be to generate every string of length l (...
-4
votes
4
answers
7k
views
Since `strcpy`, `strcat`, and `sprintf` are dangerous, what shall we use in stead of them?
In Computer Systems: a Programmer's Perspective,
Unfortunately,
a number of commonly used library functions, including strcpy, strcat, and
sprintf, have the property that they can generate a byte ...
10
votes
0
answers
266
views
Is there any guideline from Unicode on how to deal with graphemes that have no base character?
A valid sequence of code-points can begin with one or more combining mark, which form a grapheme cluster that has no base glyph.
I'm unsure how that should be handled, if at all.
For example, consider ...
-4
votes
1
answer
70
views
Choose a most probable value from the list based on some text [closed]
Im looking for a good way to find a value from the given list based on a text.
Example:
This computer has 16GB ram and with the best processor in it. Case is made from aluminium.
And I have ...
1
vote
3
answers
2k
views
Comparing whether two very large text contents are different or not efficiently
I have a MySQL database with a column Body MEDIUMTEXT. Until now I used to only store the contents into it. There was no update option for the users of the application. Now, I wanted to add an update ...
-5
votes
2
answers
133
views
In java string classes are final, than how did we enter value on string even its a final class? [closed]
In Java string classes are final, we know that we can't inherit a final class and not able to write on this, then how did we enter a value on a string even its a final class?
-2
votes
1
answer
4k
views
How to identify encoding of a text string? [closed]
I guess most of you already met them. You get them from your data sources, see them in your logs, or in the output from your legacy systems. Some strings you can't really read.
To derive any useful ...
1
vote
2
answers
4k
views
Is there a best way to insert variables into strings?
I am relatively new to programming but have noticed a lot of people when creating strings using variables do something like the below to put a variable into a string. I am curious at the difference/...
4
votes
1
answer
4k
views
Managing const strings in a Rust project
I'm looking for a way to manage constant strings in a Rust project. The hope is to manage my strings from a single file and avoid having the same string literals all over the place in the project.
...
0
votes
0
answers
59
views
Patterns for handling a Multi Responsibility Response string
We have an off shore group that is responsible for a SOAP service.
The service has a method that returns a key as a string, when everything goes correctly. When it doesn't the key is an error string. ...
3
votes
1
answer
2k
views
Should "NaN" default to SNaN or QNaN
I created a function to read floats (IEEE 754 binary 32-bit) from strings, for developers. I have everything finished and working perfectly, except i'm wondering if a user/or programmer enters a ...
2
votes
4
answers
2k
views
Should I always use iterators when working with strings?
Here is the known old way to iterate over the string:
for (int i = 0; i < str.length(); i++) {
char c = str[i];
}
However recently I have also seen in multiple places the usage of ...
1
vote
3
answers
4k
views
Find longest word in a string: are any of these algorithms good? [closed]
I'm trying to find the longest word in a given text, but it has to be done "old school": without using split, enumerate, etc. (I'm using Python but what I'm looking for is more of a ...
1
vote
1
answer
241
views
How much an iterator should do
I am working on creating iterators, for strings, lists, trees, graphs, and potentially other things.
First a side note.
I have a string data type in my engine. The string is implemented as a bunch of ...
-4
votes
1
answer
124
views
What happen to string.ToCommonSenseCase()?
I'm very confused about this. In most programming languages, there are string.ToUpperCase(), string.ToLowerCase(), sometimes Capitalize() (which capitalize the first letter of the string), even ...
0
votes
4
answers
9k
views
Is it a good idea to use strings in a struct as values to static properties?
I'm in a discussion with a co-worker concerning the use of structs. I have a couple of structs that contain several static properties that are used throughout our website. The value of those ...
2
votes
4
answers
1k
views
What is a good place, in OO, to store a string that is used many places?
I have a string that is used in a few places.
string portalLoginPath = $"{Request.Scheme}{Uri.SchemeDelimiter}{Request.Host}/Account/Login";
I was thinking of creating a static class with a string ...
0
votes
1
answer
547
views
A collision-free hash-like function for use in hash tables and other data structures?
A short introduction to the problem: I'm working with a small database where I have a table of strings (web URLs, to be precise) as pairs: hash|string. Another table references these strings by hash ...
0
votes
1
answer
710
views
Subdomain matching
I am working on a small plugin for a DNS server. I have a static list of domain (sometimes subdomains too) names:
gaming.xyz.com
facebook.com
mail.example.com
blog.example.com
I want to check if a ...
3
votes
3
answers
2k
views
Java String substring() and StringBuilder delete() methods
I've noticed that some methods like the String's substring(int beginIndex, int endIndex) and StringBuilder's delete(int beginIndex, int endIndex), use the second parameter to signify that the ...
12
votes
4
answers
2k
views
struct with nonsensical default value
In my system I frequently operate with airport codes ("YYZ", "LAX", "SFO", etc.), they are always in the exact same format (3 letter, represented as uppercase). The system typically deals with 25-50 ...
2
votes
3
answers
2k
views
Algorithm for optimizing text compression
I am looking for text compression algorithms (natural language compression, rather than compression of arbitrary binary data).
I have seen for example An Efficient Compression Code for Text ...
5
votes
2
answers
1k
views
How the rope data structure works when doing syntax highlighting
I am looking into the Rope Data Structure, used by some text editors like the xi editor.
I get the basics of how it works, and have seen some sample implementations such as here or here. But I am ...
2
votes
1
answer
549
views
Data Structure for "Intuitive" Text Matching
I've noticed that text editors and such have a more-than-prefix/suffix-based pattern matching algorithm going on behind the scenes. And StackOverflow's tag matching algorithm does more than just ...
2
votes
4
answers
3k
views
What is the optimal way to perform 5000 unique string replace functions in terms of performance?
Restructuring some code, and the way I built it up over time has portions that look something like this:
s.replace("ABW"," Aruba ");
s.replace("AFG"," Afghanistan ");
s.replace("AGO"," Angola ");
s....
2
votes
1
answer
4k
views
Efficient multiple substrings search
I have many substrings(2-5 words each) which I would like to search in some text of about 40-50 words length. What is the most efficient way to flag matching substrings.
Currently I am simply using:
...
0
votes
2
answers
11k
views
changing the value of String object in java
I have to set the value of a string object "result" depending on the results of different methods and different if/else conditions. In the end, there would be one (last value set) in the string that i ...
-2
votes
1
answer
101
views
Is it a good idea to have a string.xml to house all strings in a web application
In Android Framework there is a string.xml file that houses all the strings for the application.
This allows for easier re-use and possible internationalization. My question is, is there any ...
-3
votes
1
answer
322
views
Creating String with equal operator vs new operator? [closed]
I have seen most of times developer declares the string in below fashion
Approach 1:-
public void method1(){
String str1 ="Test";
}
Approach 2:-
Per my understanding better approach will be
...
30
votes
3
answers
24k
views
When should I use string_view in an interface?
I'm using an internal library that was designed to mimic a proposed C++ library, and sometime in the past few years I see its interface changed from using std::string to string_view.
So I dutifully ...
6
votes
1
answer
4k
views
Why doesn't Swift allow Int String subscripting and integer ranges directly?
If I have a string:
let str = "Hello world"
It seems quite reasonable to be able to extract a character:
let thirdChar = str[3]
However, that's not legal. Instead, I have to use the extremely obtuse ...
4
votes
1
answer
1k
views
Which is a more efficient approach to decoding escape sequences in text?
I'm working on parsers that not only process delimited content, but also escape sequences within certain portions of that content. I'm contemplating the efficiency of several approaches to ...
0
votes
1
answer
148
views
Simple algorithm for computing an orderable value from a string
I would like to compute a numeric value for strings containing only /[a-z0-9]/i (ignore case). Later, I want to use this value for sorting rows. For this post, I am ignoring number also.
My thinking ...
14
votes
8
answers
35k
views
Are C strings always null terminated, or does it depend on the platform?
Right now I am working with embedded systems and figuring out ways to implement strings on a microprocessor with no operating system. So far what I am doing is just using the idea of having NULL ...
6
votes
2
answers
4k
views
Detecting plagiarism – what algorithm?
I'm currently writing a program to read a body of text and compare it to search-engine results (from searching for substrings of the given text), with the goal of detecting plagiarism in, for example, ...
0
votes
3
answers
812
views
algorithm for perfect substring temporarily replacement
I have an interesting question about string and delimiters.
There is a random string str.
There are some symbols (OR SEQUENCES OF SYMBOLS) that are predefined and should be temporarily replaced ...