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.

Filter by
Sorted by
Tagged with
-3 votes
1 answer
156 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 ...
letitbesb's user avatar
1 vote
3 answers
168 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 ...
Zachary Coffin's user avatar
2 votes
4 answers
317 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 ...
MD. Mohiuddin Ahmed's user avatar
1 vote
3 answers
148 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 ...
scidhuv's user avatar
  • 29
1 vote
2 answers
221 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 ...
Hydroper's user avatar
  • 121
6 votes
3 answers
750 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 ...
Kaz's user avatar
  • 3,602
3 votes
2 answers
336 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 ...
user16217248's user avatar
  • 1,147
-1 votes
3 answers
183 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 ...
Vermillion's user avatar
-2 votes
1 answer
330 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 ...
MrSparkly's user avatar
-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 ...
Rishi Agrawal's user avatar
1 vote
1 answer
139 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:...
NPN328's user avatar
  • 218
1 vote
2 answers
277 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",...
Arunima's user avatar
  • 37
1 vote
3 answers
2k 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 ...
Lou's user avatar
  • 336
1 vote
3 answers
308 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 (...
jthulhu's user avatar
  • 141
-4 votes
4 answers
4k 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 ...
Tim's user avatar
  • 5,425
8 votes
0 answers
190 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 ...
Wes's user avatar
  • 832
-4 votes
1 answer
57 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 ...
Animal's user avatar
  • 103
1 vote
3 answers
1k 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 ...
SkrewEverything's user avatar
-4 votes
2 answers
110 views

In java string classes are final, than how did we enter value on string even its a final class?

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?
md mohiuddin's user avatar
-2 votes
1 answer
2k 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 ...
Martin Grey's user avatar
1 vote
2 answers
1k 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/...
K Emery's user avatar
  • 23
3 votes
1 answer
2k 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. ...
temarsden's user avatar
  • 139
0 votes
0 answers
51 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. ...
AthomSfere's user avatar
2 votes
1 answer
1k 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 ...
b.sullender's user avatar
1 vote
4 answers
695 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 ...
h23's user avatar
  • 121
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 ...
Floella's user avatar
  • 373
1 vote
1 answer
215 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 ...
Lance's user avatar
  • 2,585
-4 votes
1 answer
101 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 ...
AVAVT's user avatar
  • 111
0 votes
4 answers
6k 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 ...
Necromancer's user avatar
2 votes
4 answers
708 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 ...
IEnjoyEatingVegetables's user avatar
0 votes
1 answer
468 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 ...
Violet Giraffe's user avatar
0 votes
1 answer
519 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 ...
psy's user avatar
  • 137
3 votes
3 answers
930 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 ...
Steven Mcdonald's user avatar
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 ...
Matthew's user avatar
  • 1,986
2 votes
3 answers
1k 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 ...
Lance's user avatar
  • 2,585
5 votes
2 answers
845 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 ...
Lance's user avatar
  • 2,585
2 votes
1 answer
467 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 ...
Lance's user avatar
  • 2,585
2 votes
4 answers
2k 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....
Anon's user avatar
  • 3,593
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: ...
skadoosh's user avatar
  • 121
0 votes
2 answers
10k 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 ...
gogogaga's user avatar
-2 votes
1 answer
83 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 ...
donquixote's user avatar
-3 votes
1 answer
274 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 ...
scott miles's user avatar
30 votes
3 answers
20k 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 ...
T.E.D.'s user avatar
  • 1,069
5 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 ...
Duncan C's user avatar
  • 187
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 ...
rgchris's user avatar
  • 365
0 votes
1 answer
85 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 ...
user654123's user avatar
14 votes
8 answers
30k 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 ...
Snoop's user avatar
  • 2,728
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, ...
Vivian's user avatar
  • 189
0 votes
3 answers
747 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 ...
Haradzieniec's user avatar
2 votes
2 answers
484 views

Is there a good single byte delimeter for use with utf-8 strings that isn't a null terminator?

I'm looking for a quick way to split strings containing individual JSON payloads. Currently, I'm using newlines and searching for the newline ASCII character, but I figure if I start using utf-8 this ...
Mikey A. Leonetti's user avatar

1
2 3 4 5