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
1
vote
1answer
94 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
2answers
90 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",...
1
vote
3answers
253 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 ...
2
votes
3answers
113 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
4answers
317 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 ...
5
votes
0answers
105 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
1answer
47 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 ...
0
votes
3answers
219 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 ...
-3
votes
2answers
100 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?
-2
votes
1answer
136 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
2answers
411 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/...
2
votes
1answer
307 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
0answers
45 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. ...
1
vote
1answer
661 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 ...
1
vote
4answers
269 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
3answers
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
1answer
138 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 ...
-4
votes
1answer
97 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
3answers
1k 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
4answers
530 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
1answer
244 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
1answer
191 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 ...
2
votes
3answers
671 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
4answers
1k 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 ...
1
vote
3answers
366 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 ...
3
votes
1answer
378 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
1answer
342 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 ...
1
vote
4answers
419 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
1answer
3k 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
2answers
5k 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
1answer
76 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
1answer
225 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 ...
23
votes
3answers
12k 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 ...
5
votes
1answer
2k 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 ...
1
vote
0answers
130 views

speed up search in string array [closed]

Suppose we have sorted array of strings e.g. std::vector<std::string> or some other elements with string as key - for example std::vector<std::pair<std::string,data_type>. Normally to ...
3
votes
1answer
780 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
1answer
59 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 ...
13
votes
8answers
20k 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
2answers
3k 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
3answers
613 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 ...
1
vote
2answers
173 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 ...
-6
votes
2answers
294 views

Which piece of code is more efficient with respect to Time and Memory cost? [closed]

Code 1: private static int myCompare(String a, String b) { /* my version of the compareTo method from the String Java class */ int len1 = a.length(); int len2 = b.length(); if (...
12
votes
2answers
9k views

Why PHP treats “0” as FALSE in boolean contexts?

"0", as a string containing one character, is not something empty intuitively. Why does PHP treat it as FALSE when converted to a boolean, unlike other programming languages?
19
votes
7answers
2k views

Is it bad practice to store certain values as strings?

That's a very vague title but I couldn't think of a better way to word it. But, just as an example, think about the direction that a character in a game is moving in. It just feels kind of wrong to be ...
5
votes
3answers
314 views

Is it good practice to ever cast a boolean to an integer for arithmetic?

If I have a function where I am operating on a specific offset within a string, and the exact location of this offset depends on a previous test within the function, is it "bad practice" or "ugly" to ...
10
votes
5answers
744 views

Is placing text markers inside of strings bad style? Is there an alternative?

I work with massive strings which need a lot of manipulation. For example, I might generate a string like this: Part 1 Boat Section A Programming Part 2 Partitioning boats for ...
2
votes
4answers
229 views

What coding practices are most useful dealing with trailing whitespace in data fields in binary files?

We have an application that consists binary files (containing a mix of text and numeric information) and programs written in various languages that create, modify and read these binary files. Because ...
10
votes
5answers
3k views

Optimizing redundant string allocations in C++

I have a fairly complex C++ component whose performance has become a problem. Profiling shows that that most of the execution time is simply spent allocating memory for std::strings. I know that ...
0
votes
2answers
341 views

Strip spaces before saving to DB or while outputting?

Imagine scenario: need to strip out spaces from a string to be used lets say in url. Now would it be smart to do this once before saving in DB, and than use raw db results when outputting. Or would ...
-2
votes
1answer
935 views

What string will match the regular expression (^$)|(^.*\\{count\\}.*$)\n?

I'm trying to pass a parameter to create a thumbnail in AWS Elastic transcoder, which shouldn't be that difficult except I know nothing about regular expressions. My log is giving me the following ...