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
8
votes
1answer
1k views

Formatting a number

I'm writing out two numbers separated with a dash. The first number is padded with leading zeros until 6 digits, the second number, 4. ...
6
votes
3answers
6k views

Java string replace

I am new to Java and I am trying to learn about optimizing code to make it production ready. I have the following code below. I would like to know how I could optimize it. I thought by using a small ...
2
votes
2answers
3k views

Print all interleavings of two given strings

Given two strings str1 and str2, write a function that prints all interleavings of the given two strings. You may assume that all characters in both strings are different Example: ...
10
votes
3answers
471 views

Creating submenus with buttons

I have a menu, where a user selects one out of 4, and another 2 or 4 options will appear. I used big buttons; a picturebox + label to create the buttons. The 4 main buttons are fixed, but the 4 other ...
11
votes
2answers
7k views

Print all permutations with repetition of characters

Given a string of length n, print all permutation of the given string. Repetition of characters is allowed. Print these permutations in lexicographically sorted order Examples: Input: AB ...
3
votes
1answer
1k views

Decoding binary string message

I am trying to learn some Java on my own, and I am tackling some "programming challenge" problems to practice the little I have learnt so far. Could anybody constructively critique this beginner's ...
8
votes
3answers
7k views

Reversing every word in a string

Examples: char test1[] = " "; char test2[] = " hello z"; char test3[] = "hello world "; char test4[] = "x y z "; Results: ...
5
votes
2answers
2k views

Splitting a string of random length

I am currently using this code, but I am pretty sure there is a better way of doing it: ...
7
votes
4answers
634 views

Improving and optimizing squeeze() function

I am currently reading The C Programming Language by Dennis Richie and Brian Kernighan, and I came to implement the function squeeze (s1, s2) as an exercise. ...
9
votes
1answer
7k views

Implement numbering scheme like A,B,C… AA,AB,… AAA…, similar to converting a number to radix26

I want to implement numbering scheme like Microsoft Word uses for numbering. first one gets = A,next is B, next is C, .... then AA, then AB,....and so on. as shown below ...
9
votes
2answers
356 views

Command-line utility to capitalize long words in a file

I have been developing a capitalizer in Python. This is actually a script that an end user will type at their terminal/command prompt. I have made this script to: Taking the first argument as a file ...
5
votes
1answer
2k views

Parsing XML to create IList

Here's a class I created to parse XML to create an IList. It seems to me that this is something that will be done a lot in general by a lot of different programs. Is there a more standard way of doing ...
5
votes
2answers
1k views

Title case name when first, middle and last are all upper or lower case

This code works, but I get the feeling that it could be shorter and simpler. Any ideas? ...
4
votes
2answers
11k views

CoffeeScript date formatting

...
9
votes
5answers
53k views

Count the number of occurrences of a word

I was selected for the third round of MS internships for third years. We were surprisingly asked a very easy question: “Make a program that counts the number of times the WORD "a" or "A" occurs”. I ...
6
votes
3answers
3k views

A safer way to cut a string

I want to get just the first line of a big string. Currently, here's how I do it: ...
1
vote
1answer
123 views

Reversi text board parsing to bitfield

This Python code parses string representations of Reversi boards and converts them into bit string suitable for use by a bitstring module: b = BitArray('0b110') or ...
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
339 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 ...
2
votes
2answers
2k 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 ...
3
votes
4answers
11k 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
6k 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: ...
32
votes
2answers
107k 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-...
4
votes
3answers
377 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
2k 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
8k 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 ...
7
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
224 views

WMSAuth implementation

I have to implement WMSAuth in C#: http://wmsauth.org/examples ...
2
votes
1answer
137 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
445 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 ...
4
votes
2answers
18k 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 ...
11
votes
5answers
46k 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: ...
24
votes
9answers
36k 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: ...
5
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
141 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, ...
3
votes
3answers
14k 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
15k 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
69k 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? ...
7
votes
2answers
12k views

Edit Distance Between Two Strings

...