string-manipulation

compare two files in python

in a.txt i have the text(line one after the other) login;user;name login;user;name1 login;user in b.txt i have the text login;user login;user login;user;name2 after comparing it should display in a text file as login;user;name login;user;name1 login;user;name2.... How can it be done using python? ...

How to search for 3 lettered words in a column - MySQL?

I have a 'Title' column with abbreviations (Ceo, Cio,..) which I have to capitalize. What is the most efficient way of finding 3 lettered words and capitalizing them? Sample data : Title ----------------------- Vp - business, Cio, Ceo E Vp, Cfo Ceo Cio Vp Thank you so much! ...

Please suggest what is wrong with this string reversal function?

This code is compiling clean. But when I run this, it gives exception "Access violation writing location" at line 9. void reverse(char *word) { int len = strlen(word); len = len-1; char * temp= word; int i =0; while (len >=0) { word[i] = temp[len]; //line9 ++i;--len; } word[i] = '\0'; } ...

Stripping blank spaces and newlines from strings in C

Hi, I have some input like this: " aaaaa bbb \n cccccc\n ddddd \neeee " And I need to sanitize it like this: "aaaaa bbb cccccc ddddd neeee" Basically: Trim all blank spaces at the beginning and end of the string Strip all new lines Strip all spaces when there is more than one, but always leave ONE space between words I...

Insert character infront of each word in a string using C++

Hi all, I have a string, for example; "llama,goat,cow" and I just need to put a '@' in front of each word so my string will look like "@llama,@goat,@cow", but I need the values to be dynamic also, and always with a '@' at the beginning. Not knowing a great deal of C++ could someone please help me find the easiest solution to this proble...

matching a word to end of string with strpos

Solution: strpos turned out to be the most efficient. Can be done with substr but that creates a temporary substring. Can also be done with regex, but slower than strpos and does not always produce the right answer if the word contains meta-characters (see Ayman Hourieh comment). Chosen answer: if(strlen($str) - strlen($key) == strrpo...

Problem converting path string from "/", "\"

i got this code $current_path = str_replace('\', '/', getcwd()); //c://xampp/htdoc Why it fail replace '\' with '/' in directory patch ? why is the reason and how to handle this problem ? EDIT This code use to return path (or something like that) use with HTML TAG base. $current_path = getcwd(); function get_basepath() { ...

strtok wont accept: char *str

strtok wont work correctly when using char *str as the first parameter (not the delimiters string). Does it have something to do with the area that allocates strings in that notation? (which as far as i know, is a read-only area). thanks in advance example: //char* str ="- This, a sample string."; // <---doesn't work char str[] ="-...

How can I partial compare two strings in C?

Hi, Let's say I have the following content: Lorem Ipsum is simply dummy text of the printing and typesetting industry. How do I search for dummy or dummy text in that string using C? Is there any easy way to do it or only with strong string manipulation? All I need is to search for it and return a Boolean with the result. EDIT: You ...

How to split a string with a delimiter larger than one single char?

Hi, Supposing I have this: "foo bar 1 and foo bar 2" How can I split it into: foo bar 1 foo bar 2 ? I tried strtok() and strsep() but neither worked. They don't recognize "and" as delimiter, they recognize "a", "n" and "d" as delimiters. Any function to help me with this or I'll have to split by the blank space and do some strin...

Using fgets to read strings from file in C

I am trying to read strings from a file that has each string on a new line but I think it reads a newline character once instead of a string and I don't know why. If I'm going about reading strings the wrong way please correct me. i=0; F1 = fopen("alg.txt", "r"); F2 = fopen("tul.txt", "w"); if(!feof(F1)) { do{ //start sc...

What is the complexity of the below code with respect to memory ?

Hi, I read about Big-O Notation from here and had few questions on calculating the complexity.So for the below code i have calculated the complexity. need your inputs for the same. private void reverse(String strToRevers) { if(strToRevers.length() == 0) { return ; } else { ...

How is Google Calculator implemented ?

When you search in Google "100F to C" how does it know to convert from Fahrenheit to Celsius? Similarly, conversion from different currencies and simple calculation. What is the data structure used, or is it simple pattern matching the strings? ...

Successive adding of char to get the longest word in the dictionary

Given a dictionary of words and an initial character. find the longest possible word in the dictionary by successively adding a character to the word. At any given instance the word should be valid word in the dictionary. ex : a -> at -> cat -> cart -> chart .... ...

Extracting a string starting with x and ending with y

First of all, I did a search on this and was able to find how to use something like String.Split() to extract the string based on a condition. I wasn't able to find however, how to extract it based on an ending condition as well. For example, I have a file with links to images: http://i594.photobucket.com/albums/tt27/34/444.jpghttp://i59...

Complex String Processing - well complex to me

I am calling a web service and all I get back is a giant blob of text. I am left to process it myself. Problem is not all lines are necessarily the same. They each have 2 or 3 sections to them and they are similar. Here are the most common examples text1 [text2] /text3/ text1/test3 text1[text2]/text3 text1 [text2] /text /3 here/ I am...

How to find string in a string

I somehow need to find the longest string in other string, so if string1 will be "Alibaba" and string2 will be "ba" , the longest string will be "baba". I have the lengths of strings, but what next ? char* fun(char* a, char& b) { int length1=0; int length2=0; int longer; int shorter; char end='\0'; while(a[i] != tmp) { i++; le...

c# create an arbitrary length generic parameter string e.g. ?,?,?

I know I am forgetting to remember how to do this and it is late. I want to, in an elegant manner, build a placeholder list for a munged sql command. Have a command with an arbitrary number of parameters, need to build ?,?,? Did I mention that it was a wet brain fart? this is what came out: You are welcome to make me feel like more ...

Very simple regex not working

I have read that to match a word inside of a string using Regular expressions (in .NET), I can use the word boundary specifier (\b) within the regex. However, none of these calls result in any matches Regex.Match("INSERT INTO TEST(Col1,Col2) VALUES(@p1,@p2)", @"\b@p1\b"); Regex.Match("INSERT INTO TEST(Col1,Col2) VALUES(@p1,@p2)", @"\bI...

Hyphenate a random string to an exact format

Hello, I am creating a random ID using the below code: from random import * import string # The characters to make up the random password chars = string.ascii_letters + string.digits def random_password(): return "".join(choice(chars) for x in range(32)) This will output something like: 60ff612332b741508bc4432e34ec1d3e I wo...