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
3
votes
3answers
3k views

Calculating user birth information

Can you please check if I've written the code correctly? The task was: Calculate the user's month of birth as a a number, where January = 0 through to December = 11. Take the string entered Get ...
3
votes
3answers
328 views

Custom strcat() with different arguments

I am teaching myself C, and feel like I am just starting to get the hang of pointers and arrays (I come from Python, where everything is magic). I'm looking for reviews, especially if I'm doing ...
0
votes
2answers
1k views

Creating a dictionary of all prefixes of a string in Python

a=raw_input() prefix_dict = {} for j in xrange(1,len(a)+1): prefix = a[:j] prefix_dict[prefix] = len(prefix) print prefix_dict Is there any possibility of ...
2
votes
3answers
150 views

How to re-factor a common String comparison

Code below is scattered all over the code base : if (StringUtils.contains(manager.getName, "custom")){ } It just checks if an object attribute contains a ...
2
votes
4answers
10k views

Algorithm to find substring in a string

Can this be improved? ...
14
votes
3answers
5k views

Constant time string comparision in PHP to prevent timing attacks

I've been advised that when checking the password hash for a user I should use a string comparison function that always takes the same amount of time, to avoid timing attacks. So I wrote this: ...
8
votes
3answers
5k views

Approximate String Matching Interview Question

I was working on the challenge Save Humanity from Interviewstreet for a while then gave up, solved a few other challenges, and have come back to it again. The code below generates the correct ...
10
votes
3answers
16k views

Java Date formatter

The (real life) problem Following my question on SO, I found out that printing a Java Date() in a custom format is quite tedious: ...
28
votes
2answers
102k views

Integer to Alphabet string (“A”, “B”, …“Z”, “AA”, “AB”…)

So this question is prompted by two things. I found some code in our source control doing this sort of things. These SO questions: https://stackoverflow.com/questions/297213/translate-an-index-into-...
3
votes
3answers
366 views

Simple text file I/O for book data

I wanted to learn how to work with file I/O properly and found an assignment in my college papers and decided to write it: ...
2
votes
1answer
1k views

Pattern Matching with Mismatch

I have been using a slightly modified Hamming Distance algorithm for approximate String Matching for patterns and wondering if there is something better out there. The t being the length of the text ...
1
vote
2answers
1k views

Haskell: rndFile and [Char] vs IO String error

...
3
votes
3answers
4k views

String in ANSI C?

I'm trying declare a string in ANSI C and am not sure of the best way to do it. ...
2
votes
2answers
7k views

Comparing long lists of strings for the closest match

What's the fastest (quality is important too, but a little less important) way to compare two strings? I'm looking for the most efficient way to compare two strings. Some of the strings I'm comparing ...
6
votes
3answers
22k views

Splitting a string into tokens in C

I am trying to improve my skill in C, and this time by getting away from strtok. The following code splits the input string into ...
3
votes
1answer
200 views

WMSAuth implementation

I have to implement WMSAuth in C#: http://wmsauth.org/examples ...
2
votes
1answer
136 views

Is this String concatenation creating extra String?

Using the eclipse formatting on a class with some @NamedQueries created concatenations. While I have been doing this for years without paying attention I just ...
4
votes
3answers
434 views

Possible buffer overflow dangers in C log parsing program

After hours of working, I've finally finished my first C log parsing program! (previously was a bash script, now it is C). Although I think I've gotten most everything, I was just wondering if you ...
3
votes
2answers
17k views

Determining length of a char* string in C++

I was looking to do this with sizeof() and I just gave up. As minimal as I can make it, I was wondering if there was a less crude way of doing the ...
12
votes
5answers
45k views

Checking whether a string is a valid number

I'm developing a Java Helper Library which has useful methods developers don't want to type out over and over. I'm trying to think of the best way of checking whether a string is a valid number. I've ...
2
votes
4answers
7k views

A couple of basic string parsing functions

I have an app that does a fair bit of text-parsing based on free-form user inputs. In this, I run searches on the whole string, and then on the last value of the string separate from the rest of the ...
1
vote
2answers
4k views

Find two equal substrings in a string

I have various strings that contain codes, e.g. like this: "file = new JarFile(new File()" + "\nSystem.out.println(file" but also ...
0
votes
1answer
5k views

Manipulate XML files in c#

I just finished my working code, but still want to improve it. I want to transform this input: ...
23
votes
9answers
32k views

Most efficient way in C++ to strip strings

If I want to strip a string completely of its whitespaces, punctuation and numbers (i.e. anything that is not A-Z, a-z), what is the most efficient way of doing it in C++? I tried this: ...
4
votes
4answers
10k views

Build a sentence from tokens / words in a String-Array

I'm facing an interesting issue at the moment: My Situation: I'm having (in Java) String-Arrays like the following (more complicated, of course). Each String-Array represents one sentence (I cant ...
2
votes
1answer
140 views

Removing text after `:`, `:` included

I need to remove last text after : in my String and : too. I have tried this. Please review. If there is a better way to do, ...
2
votes
3answers
9k views

Splitting a string into words or double-quoted substrings

For various reasons, I'm parsing a string, this code will explain what I'm after: ...
3
votes
1answer
1k views

Balanced delimiter method

I was trying to solve the following Programming Praxis problem: Write a function that takes a string and determines if the delimiters in the string are balanced. The pairs of delimiters are (), []...
6
votes
1answer
14k views

Returning index of nth occurrence of a substring

I've built a JavaScript function returning the index of the nth occurrence of a substring in a string. ...
4
votes
2answers
59k views

Formatting a datetime string in the YYYYMMDD format

I'm working with some strange APIs that requires the dates to be sent in the YYYYMMDD format. I was thinking of doing something like this: ...
1
vote
1answer
4k views

String format function

string Format(string format_string, T1 p1, T2 p2, ..., TN pn) The Format() function takes a copy of ...
2
votes
1answer
1k views

Deleting everything between two quotes in a string

Is this the easiest way to delete everything between and including the two first quotes (if present) in an std::wstring? ...
8
votes
2answers
11k views

Edit Distance Between Two Strings

...
4
votes
3answers
20k views

String parsing in C

This is supposed to be strict ANSI C89 pedantic code. It should extract word1, word2 and ...
4
votes
2answers
796 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
497 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
760 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
923 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 ...
2
votes
2answers
1k views

Read until EOF and realloc as needed

This is a function that reads until EOF and reallocs as it goes. ...
6
votes
3answers
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
466 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
423 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 ...
24
votes
8answers
47k 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
991 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 ...