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.

learn more… | top users | synonyms (1)

4
votes
1answer
36 views

Constructing a long string

I have a task to construct a long properly formatted string in Java. This string will be then used as a header of the logfile that we write during the program execution. As the program runs on server ...
4
votes
1answer
31 views

String parsing/stripping code

I am mostly interested in how the parse_string function could be improved. But any comments on my test strategy also welcome. The input is a string which can be ...
13
votes
2answers
76 views

Playing with strings

I wanted to dust off my C skills, so I decided to write a couple string manipulation functions. I aimed for simplicity and safety. Performance was not a concern. Please be a thorough as you like. C ...
8
votes
3answers
88 views

Implementing StrStr()

This is a naive implementation - I know that there are algorithms like KMP However I was trying to implement it as best as I can. ...
2
votes
4answers
125 views

Implementing Substring in C#

I was trying just as a practice to implement substring on my own. the Test is inside the Ctor just because it is easy. ...
-5
votes
1answer
41 views

What are the Steps/Algorithm to load/Parse an XML File? [closed]

I want to write an xml parser by my own, i know to search for a string, load files into memory using vectors, but is theres a way i can use this to load and parse xml file, i were told to make a DOM ...
1
vote
2answers
51 views

Implement StringBuilder

I was asked this in an interview yesterday. I could add whatever methods, members and constructors I wanted but I couldn't change the signature of the provided ...
4
votes
5answers
727 views

String vs List to check if a country is part of a continent

I simply need to check if a country is part of a particular continent (only one). The continent has around 50 countries. The list is constant and must be initialized at the time of creation. Which one ...
3
votes
1answer
41 views

Parsing Lua 5.2 strings with patterns

I wrote some code to parse Lua 5.2 strings in Lua 5.1, using patterns. It's a bit too slow, but it works fine as far as I tested. ...
2
votes
1answer
14 views

Custom moment formats based on string length

Just wanted to gage how solid this code is. With moment cracking down on lazy formatting I thought this was a good way to parse the string for what format to use. ...
4
votes
3answers
201 views

Length of the longest sequence of repeating characters

I have been going through some CodingBat exercises and I came across this problem. "Given a string, return the length of the largest "block" in the string. A block is a run of adjacent chars that are ...
4
votes
3answers
173 views

Sorting strings with certain restrictions

I want to sort a string which contains words and integers with the restriction that if the nth element in the list is an integer it must remain an integer and if it is a word, it must remain a word. ...
5
votes
2answers
117 views

Balance braces method

This is a continuation of this question, at least the first part of that question. I want to check if everything in the new code is right or if there are other way to make it better. Exercise The ...
4
votes
3answers
129 views

String difference algorithm

I would like to get a feedback about the code below. Is there any way to improve its performance? Maybe you know input values that might print bad output? The idea of the code is to count unique ...
3
votes
3answers
262 views

Creating a string from command line arguments

I am fairly new to C and am just overcoming my fear of pointers and segmentation faults. C is a strange language to me because I come from more object oriented languages like JavaScript and Java. ...
3
votes
2answers
97 views

Finding string roots

This is the following Python code that I have coded for an algorithmic problem online. For each line of input, the goal is to find the greatest number of repeating blocks into which the string can be ...
1
vote
2answers
135 views

Effective way to remove white spaces from string

I have come up with this approach but I'm not convinced about its effectiveness. Is there any effective approach? ...
3
votes
1answer
53 views

Test if a string is a number

In need for testing if a string is a number which could be a double or integer, I wrote a simple skeleton, which parses a string like this: ...
6
votes
3answers
308 views

One character diff - string comparison

The question was: Create an algorithm to check if two strings differ by one character. This wasn't my interview, so I tried to understand the question. Options: just compare the chars one by ...
4
votes
3answers
241 views

Truncate String Method

I have 2 Truncate string methods. First: ...
5
votes
3answers
173 views

Join strings from a List<string> while also formating them

The code I have wrote works fine, this inquiry being purely for educational purposes. I want to know how others would do this better and cleaner. I especially hate the way I add the list items to ...
6
votes
3answers
114 views

Append a string to each line in a file

I wrote (several months ago) a program that will take an input file, with a provided std::string, and append that to each individual line in the file. Looking at ...
2
votes
3answers
65 views

Searching text for a string

This is my current code: ...
3
votes
1answer
101 views

Optimal string literal tokenizing algorithm

I have a tokenizer, where one of the token types happens to be a C# string type. It takes a TextReader as its input, which is created from a StringReader, and it needs to support the basic stuff C# ...
2
votes
2answers
38 views

Lua program to clean up phone numbers

How idiomatic is my code? Since Lua does not have classical inheritance such as in OO languages. Feedback on the test and implementation are both appreciated/welcomed. The rules are: If the phone ...
4
votes
2answers
54 views

Substituting Hebrew letter variants

I have two functions that replace letters. In one function, I'm replacing a regular Hebrew letter with its final form, and the other function undoes this operation. (Consider it like ...
2
votes
1answer
48 views

Using TAGS with <script> on your websites

This function creates a series of links at a desired destination by the usage of a premade tag system. Usage: createMyTAGS_DATA passes in a single line of all ...
3
votes
4answers
145 views

Reversing a string in place without using iteration in C

This is function for reversing a string in C using recursive calls: ...
14
votes
7answers
1k views

Determining whether two scrambled strings are equivalent

I was able to complete the problem doing it in this manner, but I would assume there has to be an easier way. Sample input: abc, cba Output: ...
3
votes
2answers
43 views

JavaScript/jQuery string handling

Recently I wrote some code to take two arrays of data and create a title. Each array could have 0-n elements. However, the multiple if statements seem messy to me. ...
4
votes
2answers
120 views

Testing whether a given string has unique characters

Here is my code which tests whether a given string has unique characters. The function is_unique which does a linear search for each character in the string is ...
8
votes
1answer
69 views

Karp-Rabin with bitwise hash

As a Rags-to-Riches re-implementation of the Karp-Rabin question here, from @tsleyson, I thought it would be interesting to understand the algorithm better, and to use bitwise-shifting instead of ...
5
votes
3answers
81 views

Karp-Rabin String Matching, Part 2

Part 1 is here. I wrote a Java implementation of the Karp-Rabin semi-numerical string matching algorithm. I incorporated the suggestions of @fge and @maaartinus from the other question into my new ...
4
votes
3answers
217 views

Splitting and printing comma-separated values

I stumbled upon a question on SO asking how to split a comma-separated string into individual values. Since it's been a while since I've had any good reason to write C I'd like to ask for some ...
1
vote
1answer
71 views

String search & replace in C

I created a function to do that, and I want to know if there is a problem I'm overlooking about it .. ...
7
votes
4answers
629 views

Check if two strings are anagrams

I'm doing some practice questions from the book Cracking the coding interview and wanted to get some people to review my code for bugs and optimizations. Question: Write a method to decide if two ...
4
votes
1answer
65 views

Add spaces before uppercase letters

I'm trying to convert some very simple C# string utility functions to F# as a learning exercise. Ignore the fact that the C# version is implemented as an extension method for the moment. The ...
11
votes
7answers
1k views

IsNullOrWhiteSpace check for Java

I am needing to write my own IsNullOrWhiteSpace check for Java but am wondering if this is the best method to do so ...
4
votes
2answers
68 views

Slowly working word counter

I have a problem where, given N terms, the task is to find the k most frequent terms from given N terms. My code is correct, but I have a time limit 10 seconds and my code doesn't pass. Constraints: ...
2
votes
1answer
29 views

Optimize calculation of string self-similarly with its suffixes

I am trying to solve a Hacker Rank problem about string suffixes: 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. ...
5
votes
1answer
66 views

Karp-Rabin string matching in Java

I wrote an implementation of the Karp-Rabin string matching algorithm in Java 7, based on the discussion in Section 32.2 of Introduction to Algorithms (CLRS). Clearly, I need more experience with ...
8
votes
3answers
315 views

The stripping extensions

In order to make my life easier with parsing some VBA code, I have written a few extension methods to extend the string type, and put them in this ...
9
votes
1answer
132 views

Counting Words in Files - MATLAB style

Note: this question may seem quite large, but the code to review is actually quite short For my Matlab class I'm taking, I was given the task to write a function ...
8
votes
2answers
208 views

Trim Functions in COBOL

A coworker, from a past programming life, called me up last week and asked about Trim Functions in COBOL. I sent her these PEFORMed "functions", which I've had lying about and without any professional ...
4
votes
4answers
59 views

Optimise runtime of filter character method

I'm trying to run the method below against a very large corpus and I need to optimize/reduce the run time for this method as it already takes up about 6 seconds to execute. Requirements: Check the ...
11
votes
2answers
404 views

Replace fifth space with new line

I want to replace the fifth space in a sentence with a new line. Sample input: "Hi this is empty string. This should be in new line!" Expected output: "Hi this is empty string. This ...
8
votes
5answers
313 views

Counting the number of occurrences of chars in one string, in another string

This program counts the total number of times any character from the source string can be found in the target string. E.g Source String - "Hello World" Target ...
1
vote
0answers
114 views

Calculate the average length of words in a phrase [closed]

I have a function avg_word_length(str) that takes a string and calculates the average length of the words. The input has to be cleaned up before the words can be ...
2
votes
2answers
72 views

Parse a value to a given datatype

For our (internal) automated test project, I am writing a part where parameters can be passed to an SSIS Package before it gets executed. The tester delivers the parameter name, value and desired ...
2
votes
2answers
111 views

String compression using repeated character counts

Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become ...