string-manipulation

iterating over each character of a String in ruby 1.8.6 (each_char)

Hello, I am new to ruby and currently trying to operate on each character separately from a base String in ruby. I am using ruby 1.8.6 and would like to do something like: "ABCDEFG".each_char do|i| puts i end This produces a undefined method `each_char' error. I was expecting to see a vertical output of: A B C D ..etc Is the each...

Split String in C# without delimiter (sort of)

Hi, I want to split a string in C#.NET that looks like this: string Letters = "hello"; and put each letter (h, e, l, l, o) into an array or ArrayList. I have no idea what to use as the delimiter in String.Split(delimiter). I can do it if the original string has commas (or anything else): string Letters = "H,e,l,l,o"; string[] AllLett...

Does php include toupper and tolower functions?

does php include any function like toupper and tolower I want toupper fuction which convert ABC to abc or Abc to abc simlary tolower shold convert ABC to abc or Abc to Abc ...

jquery removing string parts from two areas

I'm looking to expand on a recent script i've coded using jquery. I have this following code <script type='text/javascript'> added_departments = new Array(); $("#departments_submit").click(function(){ var depo = $("#depo_list").val(); if(jQuery.inArray(depo, added_departments) != -1) { return false; } else ...

C++ std::transform() and toupper() ..why does this fail?

Hi, I have 2 std::string. I just want to, given the input string: capitalize every letter assign the capitalized letter to the output string. How come this works: std::string s="hello"; std::string out; std::transform(s.begin(), s.end(), std::back_inserter(out), std::toupper); but this doesn't (results in a program crash)?...

Why is Perl the best choice for most string manipulation tasks?

I've heard that Perl is the go-to language for string manipulation (and line noise ;). Can someone provide examples and comparisons with other language(s) to show me why? ...

how to split a string in javascript

how to split a string in javascript? example str = "this is part 1 one wall this is part 2 " now I want to split the str in 2 parts separated by word wall so I want output to be: st1 ="this is part 1 " st2 ="this is part 2 " ...

Input string compressed as string

Hi, I want to compress/transform a string as new string. i.e.: input string: USERNAME/REGISTERID output string after compress: <some-string-in-UTF8-format> output string after decompress: USERNAME/REGISTERID There are some compress or hash method for this transformation? I prefer some solution using Java or an algorithm with ...

c string multiple replacements within a character string

Lets say I have a string: "(aaa and bbb or (aaa or aaa or bbb))" **for simplicity sake, this will always be the format of the string, always 3 a's followed by a space or ')' or 3b's followed by a space or ')'. what would be the best way to replace every occurence of 'aaa' with a '1' and everyoccurrence of 'bbb' with a '0' in C. endin...

Splitting an html string into the seperate div tags

I have a string full of html & which reads Dim strHml as string = "<html><head><title></title></head><body><div class="normal">Dog</div> <div class="normal">Cat</div><div class="normal">Elephant</div><div class="normal">Giraffe</div><div class="normal"><div><p>Random Div</p></div>Lion</div><div>Wolf</div> <div>Tiger</div></body></html>...

How do I insert a lot of whitespace in Perl?

I need to buff out a line of text with a varying but large number of whitespace. I can figure out a janky way of doing a loop and adding whitespace to $foo, then splicing that into the text, but it is not an elegant solution. ...

Remove control characters from php String

Hi all, seems trivial but give me a hard time: Does anyone have a hint for me on how to remove control characters like STX from a php string. I played around with preg_replace("/[^a-zA-Z0-9 .\-_;!:?äÄöÖüÜß<>='\"]/","",$pString) but found that it removed way to much. Is there a way to remove only controll chars? tia K ...

Java Strings to Int

Hi, I'm just stuck with a problem (maybe Simple). But I can't figure out how to solve it, maybe someone of you can help me. I receive as input an string with this format: D0001001.tiff And I need to return the next one (given that the next one is the received incremente by factor of one. Input: D0001001.tiff Output: D0001002.tiff No...

What is the most efficient way in C# to determine if a string starts with a number and then get all following numbers up until the first non-numeric character?

I have a requirement to sort some strings that contain data like this: var strings = new List<string>{"2009 Arrears","2008 Arrears","2008 Arrears Interest","2009 Arrears Interest"}; And they want the results ordered like this: "2009 Arrears" "2009 Arrears Interest" "2008 Arrears" "2008 Arrears Interest" It seems like I need to cre...

Efficent way of breaking a string into an array based on a character eg.% in C?

Could find a similar thing for C here. I need to break a sentence into a an char array based on occurrence of a character example: % Example If my sentance is my%healthy%dog then i should be able to get my, healthy and dog separately. This could be in a loop as well. tx ...

how to convert IP address from char to int

Hi! I have an IP address in char type Like char ip = "192.123.34.134" I want increment the last value (134). Does anyone how should i do it? I think, i should convert it to an integer, and then back, but unfortunately i don't know how? :( I'm using C++. Please help me! Thanks, kampi ...

Trimming A Vertical Bar

Hi guys, In PHP the trim function has a parameter for trimming specific characters (handy for leading zeros and the like). I can't seem to get it to accept a vertical bar (|) character. Anyone know how to get this working? I tried the hex value but had no luck. I'm sure it's something simple. Cheers ...

fast string modification in python

Hi all, This is partially a theoretical question: I have a string (say UTF-8), and I need to modify it so that each character (not byte) becomes 2 characters, for instance: "Nissim" becomes "N-i-s-s-i-m-" "01234" becomes "0a1b2c3d4e" and so on. I would suspect that naive concatenation in a loop would be too expensive (it IS the bo...

How to copy char *str to char c[] in C?

Trying to copy a char *str to char c[] but getting segmentation fault or invalid initializer error. Why is this code is giving me a seg fault? char *token = "some random string"; char c[80]; strcpy( c, token); strncpy(c, token, sizeof c - 1); c[79] = '\0'; char *broken = strtok(c, "#"); ...

Using strtok() in a loop in C?

I am trying to use strtok() in nested loop. But this is not giving me desired results. Possibly because they are using same memory location. My code is of the form:- char *token1 = strtok(Str1, "%"); while(token1 != NULL ) { char *token2 = strtok(Str2, "%"); while(token2 != NULL ) { //DO SMTHING token2 = strtok(NULL, ...