Questions tagged [strings]
A string is a sequence of characters. It is commonly used to represent text or a sequence of bytes. Use this tag along with the appropriate programming language being used.
2,667
questions
3
votes
2answers
174 views
Keyboard Printing with Teensy
I'm trying to write a piece of code that will mimic ASCII keyboard output. It uses the keyboard library from pjrc, but the application I'm working on requires outputting string sequences rather than ...
7
votes
3answers
755 views
2
votes
2answers
175 views
Simplify series of string manipulations in Ruby
I have a series of string manipulation, I realize this with the following code. I want it to be more elegant and readable such as ...
7
votes
1answer
1k views
Optimizing string match algorithm
I was trying to solve this problem. I thought of any possible relation between the number of matches among subsequent substrings, but could not find one. So, the probably naive solution that I ...
5
votes
2answers
3k views
Encryption/decryption of data
I'm trying to work with some encryption/decryption of data. It was some hard work for me to get it working with some buffers and what not.
This is the code I came up with:
...
2
votes
2answers
1k views
Searching for a string in a web page
I have written the below code to search for a string in a web page. This is working fine but I need suggestions on improving this code to start using this. This is written to work under IE.
...
2
votes
1answer
723 views
Finding the first and last IP in an IP range string
I'm very new to python and scripting in general. I've come up with the following function to find the first and last IP when an IP range string is inputted. I want to only use base Python (and not ...
4
votes
2answers
3k views
Random string + encrypt/decrypt
Are there any security flaws in what I plan to do?
I need to store the following in my DB:
a random string to act as a salt for encrypting a password
the encrypted password that used the salt in #1
...
33
votes
10answers
85k views
Random string generation
I'm using this C# function to generate random coupons for a system. How can I improve it?
...
5
votes
1answer
160 views
4
votes
1answer
2k views
Outputting a countdown in a div
I got this code working with the jQuery Countdown Plugin to take a string input and output a countdown in a div. Is there a better way of implementing this?
JSFiddler
HTML
...
8
votes
3answers
19k views
Replace multiple occurrences of a character
I try to replace multiple occurrences of a character with a single character.
Input:
hhiii!!! hooowww aaareee yyyooou???
Output:
hi! how are you?
...
51
votes
5answers
211k views
String.IsNullOrEmpty in JavaScript
I am aware of it being frowned upon to do something like write C# in JavaScript. (see this if you don't know what I'm talking about)
But as a judgement call, I think we could stand to have a ...
11
votes
3answers
1k views
Reusing strings read from I/O
I am working on an application that reads lots of data from the network and puts it in a grid. I noticed that I could save some memory by reusing existing strings instead of always using the new ...
5
votes
3answers
5k views
Removing any duplicate characters in a string
I have piece of code in C which removes any duplicate characters in a string. But I am doing it in two loops and would like it to optimize it to one loop.
...
3
votes
1answer
2k views
Binary search with strings
I wrote a quick and dirty program to perform binary search with an ordered array (list) of C style strings. For example:
{"1", "12", "23", "124"} etc (though my ...
4
votes
3answers
6k views
Improving the code to turn a string into an array of numbers?
I have a string of numbers, like "31654918562314", and I want to convert it into an array of integers. The code I've written is:
...
10
votes
1answer
5k views
Converting a range of integers from a string to an IEnumerable
Goal
Convert the following into an IEnumerable of integers accounting for the x-y ranges:
...
2
votes
4answers
6k views
is it a good strlcat() implementation?
I'd like to know if i respect strlcat(3) behiour with my implementation, cause i'm not really sure to understand strlcat particular behaviour
...
5
votes
1answer
4k views
Convert .NET DateTime to a string using ordinals
With a DateTime object, it's easy to get, for example, 11 October 2011 by using:
d.ToString("d MMMM yyyy");
However, there ...
6
votes
5answers
4k views
Better way to write a string slicer
Here is some code to insert a new line escape sequence after a certain number of characters (for fixed width displays)
...
8
votes
2answers
157 views
String substitutions in ruby and coding style
I wrote a short ruby script to generate various screenshots, and event though I am not completely new to ruby I rarely use it.
Full script (41 LOC): https://gist.github.com/1229115
The string ...
6
votes
4answers
469 views
1
vote
1answer
6k views
Serialization/Unserialization of a list of strings - C++
Are there any issues with below implementation?
Input: from STDIN, a list of strings
Output: serialize to a file called "out.txt" and then unserialize into a list of strings, and output to STDOUT
...
3
votes
2answers
15k views
Splitting a string in an SQL query
BudgetCode is in the format 'xxxx-yyyyy-zzzzz'. This splits it correctly but I think that there has to be a more efficient way.
...
1
vote
1answer
193 views
Encode strings by subtracting one from each character code
I currently have this encoding function which simply subtracts one from each character code:
...
5
votes
3answers
4k views
2
votes
2answers
4k views
Function to validate a file name
This function checks if a file name is valid or not. I think it's not good enough for integration (not optimized, maybe I forgot about some checks), so need your comments.
...
5
votes
1answer
565 views
Processing XML configuration which stores regular expressions and format strings for a documentation tool
I'm investigating some feature for the ScalaDoc tool, which would allow library writers to link to documentation created by third party tools like JavaDoc.
My idea is to have some (XML) configuration ...
5
votes
5answers
8k views
Determining whether a string ends with one of a few given options
I wrote the following function to determine whether a string ends with one of a few given options.
I'm sure it can be written more elegantly, probably avoiding the loop.
...
5
votes
3answers
6k views
String manipulation complexity
I've been reading Cracking the Coding Interview and at the very beginning I got to the strange statement that the next complexity will be \$O(n^2)\$.
...
3
votes
5answers
4k views
Delete each character in one string that matches any character in another
I am trying to solve an exercise in which I am given the following function:
...
6
votes
2answers
276 views
Determining which command line arguments are numeric
I am working on using STL and in general safe C++ practices. Instead of posting large samples of code I am working with a small sample to catch problems before I move onto larger ones.
How do you ...
31
votes
1answer
70k views
Pack and unpack bytes to strings
I need to write a function that "packs" an array of bytes (integers between 0 and 255) into a string. I also need to be able to perform the reverse operation, to get my byte array from the string that ...
4
votes
2answers
968 views
Remove repeated words from a 2D character array
This code removes repeated words from a word array (2D char array). I want to optimize this as much possible for speed.
...
0
votes
2answers
2k views
Command line tool for extracting, searching, and converting
I just completed my first real application (command line app). It's simple, but I had no prior knowledge of Python. Everything was hit and miss, with many Python books and help from those in this ...
3
votes
5answers
8k views
Replace sequence of strings in binary file
I have searched for method to find and replace strings sequence in binary files without any luck. The main requirement was that method should not load all file in memory but rather use chunks. I am ...
13
votes
5answers
19k views
Remove useless whitespace from styled string
I have a big string resource (basically the "about" text of the application) which contains styles (such as <b>, <a> ...
2
votes
3answers
160 views
XML-tag function
I'm an experienced programmer, but just a beginner in Python, and would like some input on a small function that's working but which I'm not very happy with.
It's used to produce XML tags (strings). ...
4
votes
2answers
771 views
Streamline code for checking if a directory exists and saving a file
I hate this code. What is the slickest way to write the following:
...
7
votes
3answers
378 views
Determining if one string occurs at the end of another
This is exercise 5-4 from K&R. I spent hours tweaking it but now it seems to work. I'm new to pointers and I'd welcome any comments about how to do it better.
...
13
votes
4answers
56k views
Simplify splitting a String into alpha and numeric parts
Requirement: Parse a String into chunks of numeric characters and alpha characters. Alpha characters should be separated from the numeric, other characters should be ignored.
Example Data:
Input ...
2
votes
2answers
280 views
Iterate comparison - How can I write this better?
I would like to write the following piece of code cleaner and more efficient, any comments will be greatly appreciated:
...
11
votes
4answers
2k views
Change upper or lowercase vowels to [0,1,2,3,4] respectively and leave the rest the same
The objective was the following to be solved in Python:
Given a string, def a function that
returns another string with the vowels
(upper or lowercase) replaced by
0,1,2,3,4 respectively.
...
14
votes
10answers
12k views
Looping through a collection
In the situation where I am looping through a collection looking for an item, is it better practice to break before I return or ...
7
votes
4answers
660 views
Managing part types and counts
Both functions look fairly similar to each other, but they are different in the type of string. I have 6 functions like this and all differ only in the "string cmd". Any ideas on how I can put it all ...
158
votes
14answers
58k views
Remove Last Comma
I want to join strings together, but when doing this it often happens that there is a comma too many, and therefore I need to remove that comma. In this code, I use the ...
11
votes
10answers
27k views
Optimizing Java Anagram checker (compare 2 strings)
An anagram is like a mix-up of the letters in a string:
pots is an anagram of stop
Wilma is an anagram of ilWma
I am going through the book Cracking the Coding Interview and in the basic ...
18
votes
11answers
1k views
Reversing a string
I had this as an interview question, and the interviewer pointed this out. Here's what I wrote:
...
2
votes
6answers
1k views
Change HashSet to a set of strings found in a file
This function changes a HashSet in the root of the class called 'commands' to a set of strings found in a file at "plugins/UC/Commands.txt" (it's what was requested by the people using the plugin). ...