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
-2 votes
1 answer
63 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 ...
user avatar
-1 votes
1 answer
754 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 ...
user avatar
1 vote
1 answer
115 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:...
user avatar
  • 208
1 vote
2 answers
199 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",...
user avatar
  • 37
1 vote
3 answers
832 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 ...
user avatar
  • 254
1 vote
3 answers
141 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 (...
user avatar
-4 votes
4 answers
2k 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 ...
user avatar
  • 5,261
7 votes
0 answers
117 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 ...
user avatar
  • 822
-4 votes
1 answer
55 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 ...
user avatar
  • 103
1 vote
3 answers
537 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 ...
user avatar
-3 votes
2 answers
106 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?
user avatar
-3 votes
1 answer
574 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 ...
user avatar
1 vote
2 answers
675 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/...
user avatar
  • 23
3 votes
1 answer
1k 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. ...
user avatar
  • 139
0 votes
0 answers
50 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. ...
user avatar
1 vote
1 answer
887 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 ...
user avatar
1 vote
4 answers
408 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 ...
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 ...
user avatar
  • 373
1 vote
1 answer
175 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 ...
user avatar
  • 2,406
-4 votes
1 answer
98 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 ...
user avatar
  • 111
-1 votes
4 answers
4k 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 ...
user avatar
2 votes
4 answers
534 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 ...
user avatar
0 votes
1 answer
366 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 ...
user avatar
0 votes
1 answer
341 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 ...
user avatar
  • 137
3 votes
3 answers
799 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 ...
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 ...
user avatar
  • 1,956
2 votes
3 answers
692 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 ...
user avatar
  • 2,406
4 votes
2 answers
610 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 ...
user avatar
  • 2,406
2 votes
1 answer
414 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 ...
user avatar
  • 2,406
2 votes
4 answers
772 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....
user avatar
  • 3,319
2 votes
1 answer
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: ...
user avatar
  • 121
0 votes
2 answers
8k 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 ...
user avatar
-2 votes
1 answer
78 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 ...
user avatar
-3 votes
1 answer
267 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 ...
user avatar
26 votes
3 answers
17k 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 ...
user avatar
  • 1,029
5 votes
1 answer
3k 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 ...
user avatar
  • 187
4 votes
1 answer
952 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 ...
user avatar
  • 365
0 votes
1 answer
77 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 ...
user avatar
15 votes
8 answers
26k 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 ...
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, ...
user avatar
  • 189
0 votes
3 answers
708 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 ...
user avatar
2 votes
2 answers
235 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 ...
user avatar
-6 votes
2 answers
302 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 (...
user avatar
12 votes
2 answers
11k 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?
user avatar
19 votes
7 answers
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 ...
user avatar
  • 367
5 votes
3 answers
374 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 ...
user avatar
10 votes
5 answers
759 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 ...
user avatar
  • 3,319
2 votes
4 answers
321 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 ...
user avatar
  • 2,510
11 votes
5 answers
5k 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 ...
user avatar
  • 607
0 votes
2 answers
546 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 ...
user avatar