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)

13
votes
4answers
569 views

Reverse a string word by word

Given an input string, reverse the string word by word. For example: Given s = "the sky is blue", return "blue is sky the". What constitutes a word? A sequence of non-space ...
5
votes
1answer
49 views

Coderbyte: String Reduction

From Coderbyte: Have the function StringReduction(str) take the str parameter being passed and return the smallest number you can get through the following reduction method. The method is: ...
-2
votes
2answers
36 views

Remove leading, trailing and repeated dashes from a string [on hold]

How do I refactor this? '-hello--world-'.chomp('-').squeeze('-').reverse.chomp('-').reverse # => 'hello-world'
-1
votes
0answers
29 views

Copy a string to another string that is in a structure in C [on hold]

Hi :) i have a question that i think for those that have programed so far will be easy. I want to know how to copy a string with 8 character to another string that have 8 character too in C language. ...
4
votes
2answers
42 views

Is my simple string tokenizer wrapper orthogonal?

I always learn something from Code Review, so if anybody could point out any bad practices in design, violations of DRY, or orthogonality problems I would be extremely grateful! #ifndef TOKENIZER_H ...
6
votes
1answer
64 views

Generate permutations with symbols

Goal: Create a combination of emails based from inputted first name, last name, middle name, and a domain. Add in common separators. Then I'll check which one is correct with the rapportive API. This ...
6
votes
2answers
47 views

Collect and calculate average times from log, then display top 10 longest durations

Here's a novel-length summary of the issue: I'm trying to write a VB.net program to help me collect remote site statistics from system-generated logs, but I'm a little like a carpenter who only knows ...
6
votes
2answers
49 views

Produce an array of strings from a single string

I have a function that reads a string like this (AnimalCount+HumanCount) and the result of this function is an array of strings [ "(" , "AnimalCount" , "+" , "HumanCount" , ")" ] Now, I have ...
1
vote
1answer
39 views

Ruby html href parser working slow

I wrote this simple HTML parser in Ruby. Basically I have a folder that has files. Every file has crawled web pages. The only addition within these files is before the HTML content there is a page ...
3
votes
2answers
94 views

Counting the words in a textarea

I've two working ways to do so, but which one should I use? Common part: var textarea = document.getElementById("textarea"); First way: function updateStatusBar() { var text = textarea.value; ...
5
votes
2answers
114 views

Removing everything after a certain character

I was just writing code, and wanted to make a piece that removes everything after the character ? if it's found within the URL. if (strstr($url, "?")) { $url = strstr($url, "?", true); } Can I ...
13
votes
5answers
1k views

Reversing the digits of an integer

For CS class, I had to reverse the digits of an integer from the input. This is my solution: System.out.println(new StringBuilder(new Integer(new ...
2
votes
2answers
67 views

How to get the Split value from collection?

I have the following key value pair in an array, and am trying to extract and load them into a collection. The below code is working but it can be optimized using Linq: string _data = ...
7
votes
1answer
55 views

Tokenizing string using strtok

In this assignment, I'm supposed to split a string using strtok. (The assignment consists of the comment and the function definition; I fill in the function body.) It works as far as I've tested. But ...
10
votes
3answers
1k views

Reverse a String in Java

Here is the code for the CString class that I created. public class CString { public String reverse(String s) { char[] array = new char[s.length()]; array = s.toCharArray(); ...
11
votes
3answers
564 views

Customised Java UTF-16

I have implemented customized encoding mechanism for javaUTF16. Does this implementation support all the characters? public class Encoding { public static void main(String[] args) { ...
5
votes
1answer
49 views

String concatenation of name parts

I have written the following function to concatenate the parts of a name to produce the full name: /** * Returns the full name of the Person. * @param boolean $includeTitle Whether to include the ...
4
votes
1answer
103 views

basic_string implementation

I have attempted to make a basic version [not complete] of the std::basic_string type in C++, and I would like to make sure that I have done everything correctly, and efficiently, as I can be prone to ...
5
votes
2answers
178 views

Writing strcat (string concatenate) in C

char *cat_string(char *to_cat, char *destination) { char *copy = destination; while (*copy != '\0') { *copy++; } while (*to_cat != '\0') { *copy++ = *to_cat++; } *copy = '\0'; ...
7
votes
3answers
147 views

Checking brackets nesting in a string

I took a training challenge on Codility that checks for the proper nesting of brackets in a string. The brackets to be checked are {,},(,),[,]. I have written the following Java program which passes ...
3
votes
2answers
97 views

Permutation of a string eliminating duplicates

This code lists the permutations of the string, and eliminates duplicates if any. I'm looking for code review, best practices, optimizations etc. Also verifying complexity: O(n! * n) as time ...
7
votes
1answer
56 views

Python compress and send

The following two functions are used to compress arbitrary Python objects and send them safely via socket or email, using only printable chars. In my specific message protocol, '=' signs are also not ...
1
vote
2answers
81 views

Calculate all possible combinations of given characters

I was asked in my textbook Lectures on Discrete Mathematics for Computer Science to construct a program that would take an alphabet ({a,b,c} or any combination of characters {1,4,s,a}) as well as a ...
5
votes
1answer
58 views

Inserting text file rows into an Access DB - Optimizing

How can I improve my inserts? I am trying to speed up the process of inserting all of the rows in my text file into an Access DB. I originally switched to this route because of the size of those text ...
9
votes
2answers
309 views

Simple dice roll using std::string as dice notation

How this could be optimized (if there any need for optimization) and what are your thoughts? This will be a function that returns a random number from Dice Notation (more on Wikipedia). I will later ...
2
votes
1answer
75 views

Refactor ConvertorToString class

Help me refactor this class that helps to represent an object state as String: public class ConvertorToString { private static final String SEPARATOR_BETWEEN_FIELD_NAME_AND_VALUE = "="; ...
4
votes
1answer
61 views

Cutting strings into smaller ones based on specific criteria

So, I've got this largish (for me) script, and I want to see if anybody could tell me if there are any ways to improve it, both in terms of speed, amount of code and the quality of the code. I still ...
2
votes
3answers
121 views

To check if a string C is an interleaving of A and B Code

This is my code to check if a string C is an interleaving of Strings A and B. Please suggests optimizations, and where I can improve. #include <vector> #include <list> #include ...
8
votes
2answers
87 views

Is there a simpler way to make an English-readable list from strings in a tuple?

I looking over some old code, I had written the function below with a C-style for-loop iterating over a count variable. I then fixed it up with new knowledge, but still am suspicious that there is ...
6
votes
3answers
93 views

Creating new string with only distinct letters

Aim: To have only one of each character on the Return string: Public Shared Function CheckForDuplicates(ByVal vCharCheck As String) As String Dim vDeDuplicated As String = "" Dim i As ...
1
vote
2answers
56 views

Reducing cyclomatic complexity in a simple string concatenation

I have written the following function that takes an address object and builds a string using the object properties. It will later be used to display a tooltip var getAddressTooltip = function ...
5
votes
2answers
263 views

Algorithm to determine if a string is all unique characters

This my solution to one of the practice problems from Cracking the Coding Interview: 150 Programming Interview Questions and Solutions [Book] implement an algorithm to determine of a string has ...
4
votes
1answer
60 views

How to make this lingo game more compact?

I made a lingo game using Python: You guess a word, and if its letter(s) is in the same spot as a hidden word's, you add [] around the letter. If it's in the hidden word, but not in the same spot, ...
6
votes
4answers
347 views

Function to convert ISO-8859-1 to UTF-8

I wrote this function last year to convert between the two encodings and just found it. It takes a text buffer and its size, then converts to UTF-8 if there's enough space. What should be changed to ...
5
votes
2answers
248 views

Finding the most common character in a string

I have started to try and work out the TopCoder problems. The "StringDup" problem asks us to: Create a class called StringDup. Given a string made up of ONLY letters and digits, determine which ...
12
votes
4answers
819 views

Better way to manipulate this string in sequence?

I am working on a small custom Markup script in Java that converts a Markdown/Wiki style markup into HTML. The below works, but as I add more Markup I can see it becoming unwieldy and hard to ...
7
votes
1answer
68 views

implementations of strncmp, strncat, strncpy

Write versions of the library functions strncpy, strncat and strncmp, which operate on the most n charachters of their argumen strings. For example, strncpy(s, t, n) copies at most n charachters of ...
3
votes
3answers
183 views

Any recommendations to improve this logging framework? Or is it overkill?

So I've been kind of irritated with my logging recently as I find myself copying and pasting the same kinds of generic messages around to lots of different methods or retyping them ever so slightly ...
10
votes
2answers
113 views

strend, function that checks the occurence of a pattern at the end of a string

Write a function strend(s, t) which returns 1 if the string t occurs at the end of s, and 0 otherwise. Here is my solution: unsigned int strend(char *source, char *pattern) { char *saver = ...
10
votes
4answers
329 views

Pointer version of strcat

Write a pointer version of the function strcat that we showed in Chapter 2: strcat(s, t) copies the string t to the end of s. This is the version of strcat from Chapter 2: void strcat(char s[], ...
5
votes
1answer
81 views

Trying multiple regexes against a single string

I have a huge list of regexes (>1,000 but <1,000,000) that I want to test against (many) single strings. It is unlikely and unintended that more than one such expression would match a single ...
3
votes
1answer
73 views

Reading and validating 2D matrix bar code

I need a review on this. This code will read a 2D matrix bar code, which I hard-coded as a string str. It has "]d" starting string, which is a GS1 International body Bar Code spec. after that. It ...
7
votes
2answers
126 views

Matching program in Java

I am new to Java and wrote one small program. It works fine, but it looks like it doesn't meet OOP concepts. Could someone look and give me advice so that I can fine tune? public class App { ...
1
vote
1answer
73 views

Determine if a std::string has all of the same character

I'm working on an algorithm to determine if a std::string has all of the same character. Here is what I have: bool string_has_all_of_the_same_chars(const std::string& s) { return ...
2
votes
4answers
147 views

Trim white space from string

This function is intended to remove leading and trailing whitespace from a string. How can it be made more efficient? For example, can the two for loops be combined into one? string trim(string str) ...
7
votes
1answer
90 views

Find the word in a string that has the most repeated characters

The problem: I want to find the word in a string that has the most repeats of a single letter, each letter is independent. Does not need to be consecutive. Currently I am jumping each character and ...
8
votes
3answers
99 views

Printing a week range string in Python

For some reporting, I need to print a human readable date string for the week covered by the report, using just the standard python module library. So the strings should look like: Dec 29, 2013 - ...
7
votes
2answers
115 views

Checking if a string matches an array of valid characters

I am wondering what a better solution would be for this bit of code: public static void main( String[] args ) { String name = "hello, ddd"; boolean[] success = new boolean[ name.length() ]; ...
4
votes
3answers
102 views

Find the longest unique string in the input list

Given a list, find the longest non-repeating (in other words I mean unique) string in the input list. Looking for code review, pointers on best practices, optimizations etc. public final class ...
5
votes
2answers
88 views

Recursive reverse function

Write a recursive version of the function reverse(s), which reverses the string s in place. Here is my solution: void reverse(char a[], int i, int j) { char tmp; if(i >= j) { ...