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.

Filter by
Sorted by
Tagged with
4
votes
3answers
23k views

String parsing in C

This is supposed to be strict ANSI C89 pedantic code. It should extract word1, word2 and ...
4
votes
2answers
800 views

“String Enum” implementation - comments?

I have a need to represent a finite set of discrete string values: When these strings are used in code, they must belong to the valid set, or serious errors (or worse) can occur. As "magic strings" ...
5
votes
1answer
521 views

Optimizing ByteString escaping

I wrote a string escaping function in C, and I'm trying to rewrite it to Haskell. The C version, along with comments explaining why it does what it does, can be found on GitHub. Here's a naïve ...
1
vote
1answer
2k views

Words counter with a hash

My problem is the following: I wrote a method, which counts words and returns a hash. There is a Ruby idiom which was found by me in some of the forums discussions, which I don't understand. Here is ...
2
votes
4answers
783 views

String-crunching routine

How can this be optimized? ...
1
vote
2answers
2k views

Finding one string located in another

Can anyone help me improve my instr() function? ...
1
vote
1answer
1k views

C-Style unsigned char parsing and manipulation

Note that I'm using a C++ compiler ( hence, the cast on the calloc function calls) to do this, but the code is essentially C. Basically, I have a ...
3
votes
2answers
1k views

Read until EOF and realloc as needed

This is a function that reads until EOF and reallocs as it goes. ...
7
votes
2answers
4k views

Replacing each string of one or more blanks by a single blank

K&R 1.9 exercise: Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank. Is this correct and proper code? Could I have put ...
8
votes
3answers
4k views

Recursive string reverse function

I'm studying C on K&R and now I'm facing a recursion exercise that states: Write a recursive version of the function reverse(s), which reverses the string s ...
4
votes
4answers
3k views

Longest substring with no repetitions

This is the code I came up with.It seems correct. I am interested in: 1) Improvements on code 2) How can it be better than this? i.e. this is O(N^2) Could I have ...
1
vote
1answer
96 views

Splitting multiple strings

I'm sure there's a better way to approach the following. I'm writing a plugin where users can enter settings in the following format: Setting: "object1setting -> object2setting" It's done this way ...
4
votes
1answer
470 views

C-string manipulation

I'd just like to get some pointers on my newbie-ish C here. The intention is to have an environment variable provide the "prefix" for any paths this app needs. For example, ...
3
votes
3answers
427 views

Entabbing a string

I am trying to finish the K&R book on C. Below is an exercise which took a long time to finish. I would like some feedback on optimization or any blatant issues with the code. Exercise 1-21 ...
25
votes
8answers
52k views

LINQ approach to flatten Dictionary to string

I have a Dictionary<string,string> and want to flatten it out with this pattern: ...
2
votes
1answer
1k views

Breaking a string into substrings

I wrote some code which divides a line through the words of the text so that each substring is no longer than MaxWidth. It works well, but it's very slow. ...
3
votes
2answers
1k views

Optimizing text drawing on screen

I'm looking to speed up this method. Ideally, I would like to cut the time in 1/2 or more. At the moment I have to draw the screen line-by-line as the font is 16 pixels high, but it is being drawn ...
3
votes
1answer
4k views

Find ASCII codes and replace with characters

I have a text file that uses the convention #\d+ to mean ASCII character number \d+. I want to replace any such representations ...
3
votes
1answer
639 views

How can I improve performance for my JavaScript table class?

I've written a JavaScript table class to make it easy to display tabular data and allow the user to sort the data by clicking on the table headers. However, when there are hundreds of rows, ...
3
votes
1answer
401 views

“Intelligent” removal of carriage returns that preserves paragraph breaks, headings, etc

It's often useful to strip carriage returns out of a plain text document, for example when copying and pasting into a field that automatically wraps lines. However, it's usually a good idea to leave ...
2
votes
2answers
24k views

Remove last word from string

Any suggestions on better way to remove the last word from a string? ...
6
votes
2answers
1k views

Word frequency generator in Python

Please critique my word frequency generator. I am a beginner programmer so any criticism are welcome. Original Code: http://pastebin.com/rSRfbnCt Here is my revised code after the feedback: ...
19
votes
3answers
69k views

Flattening a dictionary into a string

Given: k = {'MASTER_HOST': '10.178.226.196', 'MASTER_PORT': 9999} I want to flatten into the string: ...
5
votes
5answers
2k views

String traversal program in C

My task was to write a function in C where a string such as {2210090,34566,87234,564676} would be given as input and the function had to find out the count of ...
6
votes
1answer
665 views

Memory issues with Find Strings Problem on InterviewStreet

Here is the code I wrote for the problem at http://www.interviewstreet.com/recruit/challenges/solve/view/4e1491425cf10/4efa210eb70ac where we need to to print the substring at a particular index from ...
3
votes
2answers
1k views

Defensive programming in C

I wrote a function (get_last_word_of) that takes a C string and a destination buffer, and then copies the last word into the buffer. The code was originally C++, ...
26
votes
3answers
28k views

Reusing StringBuilder or creating a new one? [closed]

Given that it is better to reuse objects than create new ones when developing with Android, is it worth while deleting the contents of a StringBuilder and reusing ...
8
votes
4answers
13k views

Finding the most frequent character in a string

This is in C/C++ (using a c-string as input). I'm curious if my solution could be more efficient than it currently is. ...
1
vote
1answer
2k views

Extending string mapping

Basically I'm trying to generalise and extend the notion of mapping one string into another. There are two methods I often find myself using for this: Functions, and Dictionairies. So here are my 3 ...
13
votes
6answers
96k views

Compare items in two lists

I have a method which compares two lists of strings. If the strings, and only the strings, from listA appear in listB, return <...
6
votes
2answers
2k views

Integer to String recursive method

I was experimenting with lists, sets, and finally maps when I spotted a pattern in my code to make it recursive. Now I haven't used recursion much in the past or at work and I was very excited to have ...
3
votes
1answer
3k views

Output strings from a set in lexicographical order

Puzzle Description: You are given 'n' strings w1, w2, ......, wn. Let Si denote the set of strings formed by considering all unique substrings of the string wi. A substring is defined as a ...
6
votes
3answers
4k views

Calculating sum of similarities of strings

Puzzle: For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings "abc" and "abd" ...
4
votes
3answers
8k views

Finding duplicate strings within a file

This code basically finds duplicate strings within a file. An example: DUPLICATE_LENGTH set to 6, file contains: ...
3
votes
2answers
3k views

PHP substr slow?

If I have a long string: // 10MB string $string=''; for($run=0; $run<1000000; $run++) $string.='012345689'; Then I perform many ...
7
votes
3answers
2k views

Review on code for duplicate removal

I am trying to remove duplicates from a string without using additional buffers. This seems to work correct, I think. Can this be improved? Should I be doing it differently? ...
3
votes
2answers
670 views

Phrases update query

My query is this: UPDATE `phrases` SET `phrases`.`count`=(SELECT COUNT(*) FROM `strings` WHERE `string` LIKE CONCAT('%', `phrases`.`phrase`, '%')) My tables look ...
11
votes
4answers
14k views

Approach to string split by character in Haskell

I'm trying to learn Haskell and the mindset of programming functionally. I have started off by trying to understand the basics by writing code without any Monads in ...
3
votes
2answers
168 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
753 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
708 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 ...
32
votes
10answers
84k 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

Constructing a tail cmd

I wrote this without much thought: ...
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? ...