A string is a sequence of zero or more characters. It is commonly used to represent text or a sequence of bytes. Use this tag along with the appropriate programming language being used.
3
votes
3answers
45 views
Determine if a string has all unique characters
I'm practicing algorithms (for future interviews) while learning about Big O notation and was wondering if there's a faster or more optimal way of writing an algorithm to see if a string has all ...
5
votes
0answers
27 views
2
votes
7answers
111 views
Optimization of a String maneuvering oriented program
I've got an interview coming up for which the following is a prospective question:
Given 2 strings, for instance:
John Lennon
Paul ON
delete every character from string 1 which ...
2
votes
1answer
62 views
Encoding and decoding exercise
I was issued the following coding challenge from a company to write an encoding and decoding function:
Encoding: This function needs to accept a signed integer in the 14-bit
range [-8192..+8191] ...
8
votes
2answers
77 views
Fixing double arithmetic errors
I am trying to account for the errors in double arithmetic in a C# program I am writing, and came up with this first solution that seems to work well for most cases:
...
8
votes
1answer
56 views
Compare the index of each char in a string in an alphabet array to a range of numbers
I saw this codegolf challenge and I set out to try and write a solution for it. I'm nowhere near an expert codegolfer (or programmer), but it was an interesting exercise.
Now I'm wondering how to ...
11
votes
4answers
559 views
Split camel cased/snake cased String
I want to implement a method which, given some camelcased or underscored String, will return a list of separate words that make up this ...
1
vote
0answers
31 views
Comparing different string-matching functions
Here is a problem came from codingbat:
Given 2 strings, a and b, return the number of the positions where
they contain the same length 2 substring. So "xxcaazz" and "xxbaaz"
yields 3, since ...
1
vote
0answers
47 views
A function for parsing words from a string without using whitespace
I'm trying to parse words from a badly garbled text file that contains many repeats. It's about 100k characters in length and was formed from joining many substrings in alphabetical order.
I'm ...
7
votes
1answer
133 views
Fully-working alternative to String.format(…)
PLEASE NOTE:
The code below has "commented out" code; however, no code is actually commented out!! Check my GitHub link below. I did that solely to highlight the relevant code sections. Code in my ...
-1
votes
0answers
38 views
CyclicBarrier and Thread for optimize for element for tags in Java
How can I use A CyclicBarrier with N-THREAD according to my core for optimize this code ?
My code has an input like this:
...
3
votes
2answers
61 views
Split string into parts of varying lengths
I need to split a string into parts of varying predefined lengths, given as a sequence of integers. After a first imperative attempt using a sequence expression and a reference cell, I have now come ...
4
votes
1answer
131 views
Implement a string in reverse using pointers and recursion
I'm trying to reverse a string using pointers and recursion, and I send it a char array. Is this the best way, or is there a better one?
...
3
votes
1answer
33 views
Basic T-SQL to compare two same length strings
I've come up with the following T-SQL to compare similar same length strings.
Example usage would be:
OCR returns a value which is expected to be in the database.
PATINDEX is used to check the ...
7
votes
5answers
492 views
Split a String by an indexes array
Let's say I have a plain text string that I want to split into a string array, using an integer array containing the indexes of this string where I want it to be cut.
Example:
Input string: ...
7
votes
1answer
41 views
Homebrew std::string for use with kernel
I've ported some standard library facilities like vector, algorithm, etc. to my kernel so I can code in C++ instead of C. This is one of them. I'm looking for concerns regarding:
Performance
Safety
...
12
votes
2answers
832 views
Using large amounts of if-else statements for playing card numbers
I have a method that uses a bunch of if-else statements, and I am thinking how I could simplify it.
...
6
votes
3answers
269 views
Splitting a path string
I have the following C# method to split a path string. The only thing I know is a fixed string in the path and I have to split the full path into two parts, first part should be one level below the ...
5
votes
1answer
60 views
Renaming numbered files for proper sorting
I have designed a tool that generates some HTML files and a CSS file in a directory, which then feed into a tool called Jutoh that uses these to make eBooks.
However, my output files are of the form ...
11
votes
6answers
491 views
Efficiency with strcpy, strcat and malloc
I'm still learning C, but I'm trying to make sure I've got a decent grasp on working with "strings" and data structures.
If possible, I'd like a little input on how I'm handling this and see if
it ...
4
votes
3answers
365 views
More efficient loops to generate unpronounceable words
I wanted to write a function to generate only unpronounceable words. I realised afterwards that the same thing could probably be achieved by just taking out the vowels. Regardless, I feel that there ...
7
votes
3answers
189 views
Function to convert from const char * to char**
I made an adapter function to convert a const char * to char ** splitting the words in the initial string at each white space ...
4
votes
1answer
32 views
String encryption function in admin section
I have been using this function locally to encrypt strings for example a username.
If the user successfully logged in, place the encrypted username into a ...
7
votes
5answers
446 views
Refactoring String manipulating method with TDD
I'd like to refactor my extractSimplePromptName test so it does the same but it's "prettier", hence less code. As far as looking at it, it seems like it could be ...
1
vote
2answers
137 views
Grouping string to list of strings
The following is function that I have written to group a string to groups, based on whether there's consecutive repeated occurrence. Fop example AAAABBBBAAB is ...
12
votes
5answers
1k views
Reverse words in a given String
I'd like this code to be improved
Input string: codereview is awesome
Output string: awesome is codereview
My approach:
...
2
votes
2answers
24 views
Performance of RegExp vs Rune Loop
I was recently talking to someone about a function I wrote to mimic (very basically) the string interpolation function String.Format() found in the C# language. ...
2
votes
1answer
82 views
Getting rid of certain HTML tags
This code simply returns a small section of HTML code and then gets rid of all tags except for break tags.
It seems inefficient because you cannot search and replace with a beautiful soup object as ...
3
votes
2answers
44 views
Align text (left, center, right) without additional packages
I wrote this short subroutine to left, center, right-align a multiline string.
How can I make it better (shorter, prettier, optimized)? Can you offer some suggestions?
...
2
votes
1answer
89 views
Opening contents of a file using Swing and SwingWorker class
I want to open a file contents using swing. For this I used the SwingWorker class. This application took more time (more than a minute) to load a large file ...
3
votes
2answers
59 views
Tail-recursive query string builder in F#
I have a situation where I'm generating a URL based on a set of query string parameters for use in an API. I know ahead of time that the values passed to this function are URL-safe and the tuples are ...
5
votes
2answers
188 views
Converting a boolean list to string, and vice versa
I am currently using this to convert a List of booleans to a string
...
3
votes
2answers
50 views
Go string formatting
I'm very new to Go, and am trying to get some experience by re-writing some of my Python code in Go. Below is a function that takes an IP address (ipv4) in integer form and returns the string ...
2
votes
0answers
31 views
Checking substring in 8086 ASM
I have tried like this to check a substring in a mainstring in 8086. Is there any shorter way of doing this? My implementation seems lengthy.
...
16
votes
2answers
693 views
8
votes
3answers
69 views
Replacing the occurence of the character in string
Given a string (for example: "a?bc?def?g"), write a program to
generate all the possible strings by replacing ? with 0 and 1.
...
3
votes
2answers
114 views
Adding string binary numbers
My requirement is to add two binary numbers, say "1001" and "0101" as binary1 and binary2.
...
11
votes
3answers
118 views
Recursive, nested list traversal
Given a nested list of strings (which may contain other nested lists), print the contents of the list and the corresponding depth.
Here is my solution:
...
4
votes
2answers
100 views
Converting a string to various number formats
I'm working on a set of PostgreSQL helper classes, and am representing each PostgreSQL data type as objects. Instead of creating a class for each number format, I've created a template so the user can ...
10
votes
4answers
500 views
Integer seconds to formated string mm:ss
I have a String like "Time left (XX)" or "You need stay here for (XX)" and int as second. I use those two variables to format ...
8
votes
2answers
314 views
Remove Empty String array from ArrayList
I am trying to remove empty a String array from ArrayList:
...
8
votes
1answer
128 views
Very simple PostgreSQL ORM in C++ using libpq
I'm working on a set of helper classes for working with libpq in C++ and I want to be able to pass in objects to the helper classes and have them internally represented as strings when sent to the db, ...
4
votes
1answer
138 views
Recursive function that generates the permutations of a string
I am looking for a review of my recursive function that generates the permutations of a string. Are there better ways to do this?
...
6
votes
2answers
74 views
Convert numbers into a textual form
So this was originally inspired by @nhgrif's Int extension for translating integer to plain English, however the code is mainly a port of @rolfl's Converting a number to the text representation; ...
6
votes
2answers
93 views
Trim() every string in a JavaScript object?
We have a database with fixed width columns. The API is really simple and returns everything the database does with little to no actual processing. This results in some unnecessarily long strings in ...
1
vote
2answers
94 views
Extract numbers from an AlphaNumeric string
I have an alphanumeric string like sdff45hg589>@#DF456&<jk778P&&FHJ75, of which I want to extract only the numbers, without using regex or any ...
1
vote
6answers
134 views
Looping through an array of strings containing approximately 3 million lines of strings
I have a function that loops through an array of strings containing approximately 3 million lines of strings. My problem is this loop is running too slowly and I want to know how to make it faster.
...
12
votes
2answers
409 views
Efficiency/design of trim() library code
I am working on some library code and I am trying to optimize my trim() functions. To that effect I am trying to figure out how best to deal with each kind of ...
7
votes
5answers
370 views
Finding the most frequently used sequence of characters in a comma-delimited input string of words
I'm making a demo program for a job interview and I'd like to know if there is anything I can make work faster in my current solution. It's a C# console application that accepts input in form of a ...
3
votes
3answers
268 views
Split string by character in Java
I have this code, which goes through a string and split it using a char delimiter.
I am concerned where it can be improved.
Main concerns are speed and memory usage with speed as the priority.
Any ...