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)

1
vote
1answer
15 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
64 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
46 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
57 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 ...
-2
votes
0answers
26 views

I have an array of strings and want to access each as a character array. How do I do this? [closed]

I have an array of strings and want to access each as a character array. How do I do this? I use the below commands to create the array of strings from a text file. // Open the file $fp = ...
1
vote
6answers
133 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
1answer
47 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
24 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
65 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 ...
0
votes
0answers
21 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
23 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
43 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 ...
0
votes
0answers
50 views

Differentiating String/Int User Input [closed]

I am having issues trying to type code that will make my program distinguish whether the user inputs a string value or an int value. If an int value is typed in, it will be stored into an array (named ...
2
votes
7answers
646 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
90 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
83 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
93 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 ...
2
votes
1answer
47 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
57 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
150 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
138 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
300 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
165 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
112 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
235 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
108 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
322 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
112 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
125 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
149 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
169 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
84 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
71 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
402 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
41 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
78 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
125 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
46 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
94 views

String Building

Before, I had this code, sometimes it is longer: String dbEntry = "idBldgInfo = '" + currentBldgID + "',scenario = '305',installCost='" + installCost + "',annualSave='" + annualSave + ...
-2
votes
1answer
40 views

Most effiecient way to compare a string and an Array [closed]

I want to compare a string and an array like this, string str1 = "Ceo, Hr, Coo, Mccal"; string[] str2 = new string[] {"CEO", "COO", "HR", "McCal","CSU","PSU"}; I want to check if str2 has a ...
0
votes
0answers
50 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
132 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 ...
1
vote
1answer
252 views

first non-repeated character in a string in c

Write an efficient function to find the first non-repeated character in a string. For example, the first non-repeated character in "total" is 'o' and the first non-repeated character in "teeter" is ...
0
votes
3answers
290 views

Run Length Encoding

Given an input string, write a function that returns the Run Length Encoded string for the input string. For example, if the input string is “wwwwaaadexxxxxx”, then the function should ...
1
vote
1answer
146 views

Code review for recursion to map phone number to strings

I am trying to solve the following via recursion: In a phone we have each digit mapped to a number. Example: 1 2(ABC) 3(DEF) 4(GHI) 5(JKL) 6(MNO) 7(PRS) 8(TUV) 9(XYZ) * 0 ...
8
votes
4answers
314 views

Count words in a C string

I have a string that must be splitted into an array of strings so using strtok makes perfect sense but before that I want to allocate the array of strings and thus I count how many words in it. ...
4
votes
1answer
273 views

efficient looping procedure to find the longest common substring java

I retrieved 200 tweets using jersey API. I want to find two tweets which have the longest common substring. This is what I have got. tweetList is an ArrayList of Tweet Objects. comapreTweets method ...
8
votes
2answers
228 views

String join of distinct string

I have a class like this one: class EmailClass { public string MailAdresse { get; set; } public string MailAdresseCC { get; set; } } Through a JSON deserialization I obtain a ...
-1
votes
1answer
112 views

String.compareTo method to compare [closed]

I'm pretty new to java and don't really know about these stuff and it's my first time writing these methods! of course I have no clue how I can write them. will you check my Method and let me know ...
0
votes
2answers
224 views

Given a sequence of words, print all anagrams together

Given an array of words, print all anagrams together. For example, if the given array is {“cat”, “dog”, “tac”, “god”, “act”}, then output may be “cat tac act dog god”. My idea is to sort ...

1 2 3