string-manipulation

Replace all spaces in a string with '+'

I have a string that contains multiple spaces. I want to replace these with a plus symbol. I thought I could use var str = 'a b c'; var replaced = str.replace(' ', '+'); but it only replaces the first occurrance. How can I get it replace all occurrances? ...

Scheme String Help

I am trying to write a function that evaluates to the number of distinct characters in the input string str. So for example (distinct-char "eeeiicczz") would return 4. I need some help with my code. This is what I have. (define string-contains (lambda (str char) (if (equal? str "") #f (if (char=? (string-ref str 0...

How to remove a carriage return from a string in C ?

Possible Duplicate: Remove characters from a string in C Do you have an example of C code to remove carriage returns in a string? ...

Tokenize an environment variable and save the resulting token in a char**

Hi. I'm attempting to create an array of strings that represent the directories stored in the PATH variable. I'm writing this code in C, but I'm having trouble getting the memory allocation parts working. char* shell_path = getenv ("PATH"); char* tok = strtok (shell_path, SHELL_PATH_SEPARATOR); int number_of_tokens = 0, i = 0; while (...

Interview Question-Concatenate two Strings without using strcat in C

Recently I attended an interview where they asked me to write a C program to concatenate two strings without using strcat(), strlen() and strcmp() and that function should not exceed two (2) lines. I know how to concatenate two strings without using strcat(). But my method has nearly 15 lines. I dont know how to write it in two lines. ...

Is there a simpler way of printing a PHP array in a string?

Hi All As you know, a good programmer is a lazy programmer, but I'm just lazy. My question is this: Is there a simpler way to print out an element of an array (from a MySQL query) in a PHP echo statement? I usually do this: echo "string start " . $array['element'] . " string end"; It works FINE, I'd just like a shorter way of printi...

Take a part of a string (PHP)

We are trying to get certain parts of a String. We have the string: location:32:DaD+LoC:102AD:Ammount:294 And we would like to put the information in different strings. For example $location=32 and $Dad+Loc=102AD The values vary per string but it will always have this construction: location:{number}:DaD+LoC:{code}:Ammount:{number} S...

altering a string with PHP

If I have filename.jpg, with PHP how would change it too filename123456789.jpg, where 123456789 is a timestamp, I currently do this, $name = $filename; $parts = explode(".", $name); $filename = $parts[0].time().'.'.$parts[1]; however this just just leaves me with 123456789. ...

Format string using multiple specifiers

Is there a way to use Int32.ToString("<some string format specifier>") with using more than 1 specifiers? Specifically, I want to format an int in Hexadecimal but force the string to be 8-bit long, by adding 0's in the empty spots. For example, I want to parse the number 1234 in decimal to the string "000004D2". The way I wanted to do t...

String formatting using C#

Is there a way to remove every special character from a string like: "\r\n 1802 S St Nw<br>\r\n Washington, DC 20009" And to just write it like: "1802 S St Nw, Washington, DC 20009" ...

Complicated problem. Need help with regular expression replace.

Hello, I'm in the process of updating a program that fixes subtitles. Till now I got away without using regular expressions, but the last problem that has come up might benefit by their use. (I've already solved it without regular expressions, but it's a very unoptimized method that slows my program significantly). TL;DR; I'm trying ...

How Parsing string between [STX] and [ETX] using C# - Split/Append output using Regex or String Functions

Language = C#.NET Anything that is between [STX] and [ETX] must be accepted rest of the things must be rejected. string startparam = "[STX]"; string endparam = "[ETX]"; String str1 = "[STX]some string 1[ETX]"; //Option 1 String str2 = "sajksajsk [STX]some string 2 [ETX] saksla"; //Option 2 String str3 = "[ETX] dksldkls [STX]some stri...

How do I pass a string to a linked list instead of an array of characters in C?

I understand that there's no String data type in C. What I want to do is get an input string from the user and store it to a variable without having to define how many characters it needs to have. Can I do that using linked lists? I want to avoid putting it to a character array as much as possible so linked lists are the only thing I can...

Replicating Codeigniter's humanize() and underscore() function in Javascript

I'm trying to replicate CI's humanize() and underscore() function in Javascript. From the CI documentation, underscore() takes multiple words separated by spaces and underscores them while humanize() takes multiple words separated by underscores and adds spaces between them. The CI implementation looks something like: function unders...

What is a more elegant solution to these nested if/elseif statements?

I'm building a website that contains users with user profiles. Many of the fields in the profile are optional. There is an opportunity for a lot of user-generated content, and so I need to display the author of this content in many different locations of the site (comments, posts, etc.). In the user's profile, he is able to (optiona...

Extract an undetermined number of integers from a string

I was wondering whether there's a better way of doing this; say we read stdin to a string using fgets() where the string includes a total of n integers (e.g. 5 16 2 34 for n = 4), what would be the best way of extracting them? There has got to be a better way than this hack: for (i=0, j=0; i<n; ++i, j+=pos) sscanf(string+j, "%d%n",...

LINQ list to sentence format (insert commas & "and")

I have a linq query that does something simple like: var k = people.Select(x=>new{x.ID, x.Name}); I then want a function or linq lambda, or something that will output the names in sentence format using commas and "ands". {1, John} {2, Mark} {3, George} to "1:John, 2:Mark and 3:George" I'm fine with hardcoding the ID + ":" + Name...

Haskell split lines into list including empty lines

So have this type DocName = FilePath type Line = (Int,String) type Document = [Line] splitLines :: String -> Document splitLines [] = [] splitLines str = zip [0..(length listStr)] listStr where listStr = [getLine] ++ map snd (splitLines getRest) ...

C# Remove Invalid Characters from Filename

I have data coming from an nvarchar field of the SQL server database via EF3.5. This string is used to create a Filename and need to remove invalid characters and tried following options but none of them works. Please suggest why this is such an understandable mystery? Am I doing anything wrong? I went though almost all of the related ...

Remove chars in a string until numeric is found in ASP and VB

I am trying to add to a page that someone else has written. I need to take a string that is formated with either 3 or 4 alpha characters followed by a series of numbers. I need to remove these alpha characters so that only a string of numbers is left. Example: What I'm string with is TrailerNumber = "CIN0012345" and I need the result ...