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
6answers
294 views

Number of words in a string

I wrote this pretty simple program (it's an exercise from a book). It counts the words in a simple string. The book is a very old one (I think it's from 2003) and uses char arrays. Because of this, I ...
-1
votes
1answer
27 views

How can I map dynamic index in the string using c# [on hold]

string originaltext = "A man meet a man"; charArray[0]='A'; charArray[1]=' '; charArray[2]='m'; charArray[3]='a'; charArray[4]='n'; charArray[5]=' '; charArray[6]='m'; charArray[7]='e'; ...
1
vote
1answer
52 views

Automatically indent a whole block of text into str.format

I wondered if there was any better way of doing so. I had a hard time figuring it out (it seemed nobody else already tried to do so). import re import string class BetterFormat(string.Formatter): ...
0
votes
1answer
68 views

Python abilities on strings

the Encoding scheme is given below: Don't replace the characters in the even places. Replace the characters in the odd places by their place numbers . and if they exceed 'z', then again they ...
2
votes
2answers
119 views

Is there a better way of making an NSString with many argument values?

I have a form that I'm turning into a string value for an email, but the string value that I turn it into seems very complicated, plus I believe this way takes up a lot of memory and is somewhat slow ...
3
votes
3answers
179 views

Random String generator in C

I created this small function just to practice C code. It's a simple random string generator. #include <string.h> #include <time.h> char *randstring(int length) { static int ...
2
votes
1answer
71 views

Efficient way to copy unordered String into ordered String

I'm doing this in Hadoop Java where I'm reading a String. The string is huge that has been tokenized and put in an array. It has key-value pairs but they are not in any order. I want this order to be ...
2
votes
1answer
85 views

String Interpolation / Word Matching with XML in C#

I'm working on a project where I need to map XML values to field names. Classic CS problem, I think I've got a pretty good approach but would like feedback. For example: breachReportType matches to ...
1
vote
2answers
79 views

Custom Script Editor

I'm making my own script editor (in this case for Arma: Cold War Assault) because I want to learn and this is challenging enough. Let me just get this out of the way: please don't tell me that I ...
1
vote
1answer
65 views

Ruby string splicer

So I came across an interesting problem awhile back, and I finally got around to solving it. Basically, it needs to allow the user to provide two words, and have them progressively splice together, ...
3
votes
1answer
63 views

Trim certain characters from a string in javascript

I want to remove not only spaces, but certain characters aswell from the beginning or end of a javascript string. function trim(str, characters) { var c_array = characters.split(''); var ...
1
vote
1answer
41 views

Implementation of String object as an exercise

I am reading "Object-Oriented JavaScript" by Stoyan Stefanov to learn JavaScript and in the end of the chapter named "Objects", there's an exercise that asks you to implement your own String object. I ...
1
vote
1answer
109 views

A better approach to parsing this file name in Java?

I am creating a file uploader, and one function of the uploader will parse the file name to make sure that it is in the correct format. This is the proper format of the file name: ...
1
vote
1answer
65 views

Split and word count in go

Could it be written better? package main import ( "code.google.com/p/go-tour/wc" "fmt" ) func WordCount(s string) map[string]int { dict := make(map[string]int) splited := Split(s) ...
3
votes
1answer
104 views

String processing in JavaScript

We have a lot of phone numbers that contain dashes and start with a zero which are from another country. I am trying to strip the dashes and the one leading zero and select the country code from a ...
1
vote
6answers
150 views

Remove specific consecutive element in array

I'm trying to reduce consecutive elements of array to one, but not for all values like: {3,0,0,0,3,3,3,0,0,0} => {3,0,3,0} but for specific one, in my example 0: {3,0,0,0,3,3,3,0,0,0} => ...
1
vote
2answers
120 views

PHP spell checker with suggestions for misspelled words

I built a simple PHP spellchecker and suggestions app that uses PHP's similar_text() and levenshtein() functions to compare words from a dictionary that is loaded into an array. How it works is ...
-1
votes
1answer
36 views

Java input string from .csv file [closed]

I am very new to Java and I am trying to compile "+" in the file Reactions.csv. Here's what I have so far: // Trial.java import java.io.*; import java.util.Arrays; import java.util.ArrayList; import ...
3
votes
2answers
69 views

How to refactor this Ruby method?

The new_string code in this method does not seem idiomatic. The goal is to not mutate the string passed in, which I believe is a good practice. This method changes all URL's in the string into an ...
1
vote
0answers
23 views

reading input from keyboard

I am required to read from an keyboard(stdin), the following text. Pl note that it will be entered by user from keyboard in this format only. #the total size of physical memory (units are B, KB, MB, ...
0
votes
0answers
26 views

String Matching

I recently came across a lecture on DFA. I tried to use it to determine whether a given 'search string' is found in the 'input string'. Please tell me if there is a better way (display "Enter input ...
0
votes
0answers
57 views

JavaScript regular expression literal as string literal

Please refer to this question for more discussion. JavaScript string literal sometimes to many escaping slashes. The following address this problem by converting a regular expression literal into a ...
2
votes
7answers
829 views

String manipulation in Java

Here is the question followed by my program which works good Given a string, return a version without the first 2 chars. Except keep the first char if it is 'a' and keep the second char if it is 'b'. ...
4
votes
1answer
106 views

Ruby: refactor simple string method for aligning DSV text

GOAL: Accept DSV strings where the delimiter may consist of more than one character Accept DSV strings where there are no embedded delimiters Output text with no modification to the source string ...
1
vote
1answer
86 views

High School Java Class: Pong Project External Reviewer

Panelball class: import java.awt.*; import java.awt.event.KeyEvent; import javax.swing.*; public class Panelball extends JPanel implements Runnable { private static final long ...
2
votes
1answer
179 views

Java - Is this the correct implementation of a timer/timertask to destroy a process that overruns a defined time limit

I was wondering if this is the correct implementation of a times task to destroy a thread after it overruns a predefined time period: it works by creating a getting the thread from ...
3
votes
1answer
74 views

Generating random strings

I've created the following string manipulation function for randomizing my passed string in Lua: require "string" require "math" math.randomseed( os.time() ) function string.random( self ) ...
2
votes
1answer
69 views

LISP - Modify string

I have to write a program that changes a string's vowels, consonants and other symbols into C, V respectively 0. I've done this but I wonder if there is a more efficient and elegant way to do it. ...
1
vote
4answers
159 views

How could this postfix notation program be improved?

My postfix program allows the user two options one option for calculating a postfix equation: * Confirmations after each input (after an input, the user is ask for another number, operator, or final ...
2
votes
2answers
154 views

string to integer (implement atoi)

Implement atoi to convert a string to an integer. Requirements for atoi: The function first discards as many whitespace characters as necessary until the first non-whitespace character is ...
1
vote
1answer
517 views

Faster JavaScript fuzzy string matching function?

I'm using the following function to fuzzy match strings: function fuzzy_match(str,pattern){ pattern = pattern.split("").reduce(function(a,b){ return a+".*"+b; }); return (new ...
2
votes
1answer
214 views

JAVA, Twitter4j insert tags around entities in body

Because we're passing object to Spring Framework in which Jackson classes convert them into JSON as a reposnse we chose to Implement more simple Tweet class rather than the twitter4j provided Status ...
3
votes
3answers
113 views

Length of last word

Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist, return 0. Note: A word is ...
3
votes
1answer
476 views

Dynamically allocated C strings in C++, concatenation, pointers, etc

I'm writing a small Win32 Console app that manipulates the contents of binary files. It accepts the filename as a command line parameter and writes to a file named filename.scramble This is the first ...
3
votes
1answer
130 views

Crtitique my Haskell function 'capitalize'

I am a Haskell beginner. I wrote the following function that takes a string and returns a new string with each word capitalized: first letter uppercase, following letters lower-cased. It works, but I ...
2
votes
1answer
453 views

Get metadata from an Icecast radio stream

I am new to Python and not very familiar with advanced Python data structures. I have written a function to receive data from a socket in Python and perform string manipulations on it. The basic ...
2
votes
1answer
119 views

Too slow two strings comparer

I have 2 strings for example: abcabc and bcabca or aaaabb and abaaba I checked that second string is the same or not like first string but shifted. bcabca = ..abca + bc... Here is code it works ...
0
votes
2answers
139 views

Elegant function to “increase” a JavaScript string - for example, turning “aac” into “aad”

I'm writing a function to increase a string so, for example, "aac" becomes "aad" and "aaz" becomes "aba". The result is horribly inelegant, I can't get it simple enough and I feel I'm missing ...
3
votes
4answers
158 views

Can this string parse be improved?

My data is in this format: 龍舟 龙舟 [long2 zhou1] /dragon boat/imperial boat/\n And I want to return: ('龍舟', '龙舟', 'long2 zhou1', '/dragon boat/imperial boat/') In C I could do this in one line with ...
2
votes
1answer
243 views

Python 3: Finding common patterns in pairs of strings

I have written a piece of code that finds common patterns in two strings. These patterns have to be in the same order, so for example "I am a person" and "A person I am" would only match "person". The ...
3
votes
1answer
96 views

A reliable way to remove consecutive appearances of a substring

I'm attempting to write a piece of code that is supposed to remove consecutive appearances of a string (not a single character) in a StringBuilder. It's extremely important that the method works well ...
0
votes
1answer
103 views

Skiena's Programming Challenge [UVa ID 10137]- Getting WA

Question from Skiena's Programming Challenges. Getting WA (wrong answer) in Online Judge even though it's working for sample test cases. Can somebody find a case where it fails? I tried the tricky ...
4
votes
3answers
517 views

Longest common substring

I wrote a program to find the longest common subsequence among several strings. I used a naive algorithm and implementation. The motivation was solving the Rosalind problem at ...
2
votes
3answers
44 views

Flexible multiple string comparision to determine variable value

I've a web form that allows users to create clusters of three sizes: small, medium and large. The form is sending a string of small, medium or large to a message queue, were job dispatcher determines ...
4
votes
1answer
87 views

Nicely tabulate a list of strings for printing

I have a list of strings of variable lengths, and I want to pretty-print them so they are lining up in columns. I have the following code, which works as I want it to currently, but I feel it is a ...
2
votes
2answers
149 views

Trim function in C

I am trying to write an idiomatic trim function in C. How does this look? Should I instead malloc the new string and return it? void trim(const char *input, char *result) { int i, j = 0; for (i = ...
0
votes
1answer
81 views

split up a string into whitespace-seperated fields

I am trying to improve my C skills, and I hope someone might be able to provide me with some feedback on the following code. I avoid strtok function intentionally. #define MAX_SIZE 1000 int ...
3
votes
2answers
102 views

String Building

Before, I had this code, sometimes it is longer: String dbEntry = "idBldgInfo = '" + currentBldgID + "',scenario = '305',installCost='" + installCost + "',annualSave='" + annualSave + ...
0
votes
0answers
53 views

custom cmdline implementation

The below program takes the inputted string from commandline and parses it and calls the corresponding function. commands are either single word or multiple words. say for e.g. -#version ...
2
votes
1answer
147 views

Inefficient usage of string.format?

I have some sample code where I used string.Format but after reading about benchmark performances by other people I believe that it may be better to do multiple appends by a StringBuilder Here is the ...