string

Holding variables in memory, C++

Today something strange came to my mind. When I want to hold some string in C (C++) the old way, without using string header, I just create array and store that string into it. But, I read that any variable definition in C in local scope of function ends up in pushing these values onto the stack. So, the string is actually 2* bigger t...

Code Golf: Word Search Solver

Note: This is my first Code Golf challenge/question, so I might not be using the correct format below. I'm not really sure how to tag this particular question, and should this be community wiki? Thanks! This Code Golf challenge is about solving word searches! A word search, as defined by Wikipedia, is: A word search, word find, wor...

How can I extract a substring from a string using regular expressions?

Let us say that I have a string "ABCDEF34GHIJKL". How would I extract the number (in this case 34) from the string using regular expressions? I know little about the regular expressions, and while I would love to learn all there is to know about it, time constraints have forced me to simply find out how this specific example would wo...

IndexOf method returns 0 when it should had return -1 in C# / Java

A friend of mine came to me with this strange behavior which i can't explain, any insight view would be appreciated. Im running VS 2005 (C# 2.0), the following code show the behavior int rr = "test".IndexOf(""); Console.WriteLine(rr.ToString()); the above code, print "0" which clearly show it should have return -1 This also happen i...

is there a way to use cin.getline() without having to define a char array size before hand?

Basically my task is having to sort a bunch of strings of variable length ignoring case. I understand there is a function strcasecmp() that compares cstrings, but doesn't work on strings. Right now I'm using getline() for strings so I can just read in the strings one line at a time. I add these to a vector of strings, then convert to cst...

help with making a password checker in java

Hello, I am trying to make a program in Java that checks for three specific inputs. It has to be 1. At least 7 characters. 2. Contain both upper and lower case alphabetic characters. 3. Contain at least 1 digit. So far I have been able to make it check if there is 7 characters, but I am having trouble with the last two. What should I put...

How to compare string with float? in Objective C

How would you? I'm having problems. Thanks. I'm currently using if (myString == myfloat) { // do something but this won't work } OR if ([myString == myFloat]) { // do something but this won't work } Thanks! ...

Need to format character precedence in Strings.

I'm currently writing a Roman Numeral Converter for the fun of it. The problem works up to the aforementioned character precedence. Since Roman Numerals are not positional, i.e. III does not symbolize 1*whatever base^2 + 1*whatever base^1 + 1*whatever base^0. That of course makes it hard when somebody types in XIV and I need to make su...

Find Nth occurrence of a character in a string

I need help with creating a C# method that returns the index of the Nth occurance of a character in a string. For instance, the 3rd occurance of the character 't' in the string "dtststx" is 5. ...

What's the fastest way to convert a string of text into a url-safe variable?

I'd like to convert a string of text, e.g., "User Name" into something which I can turn into part of a url, e.g., "User-Name." What's the fastest way to do a string replacement ("-" for " ") as well as make sure that characters are only [a-zA-Z0-9]? ...

How do I convert a single char in string to an int

Keep in mind, if you choose to answer the question, I am a beginner in the field of programming and may need a bit more explanation than others as to how the solutions work. Thank you for your help. My problem is that I am trying to do computations with parts of a string (consisting only of numbers), but I do not know how to convert a...

Switch-Case for strings in Javascript not working as expected

So I have this problem with strings and switch-case, and I'll try to keep it as simple as possible. Here event.keyCode has the value "65", and is the result of a keydown event of 'a' (using JQuery). if (event.keyCode == "65") { alert("hmmmm"); } That works, but: switch (event.keyCode) { case '65': alert("Yay!"); b...

How to extract a couple marked strings from a line (python)

My Friends, I spent quite some time on this one... but cannot yet figure out a better way to do it. I am coding in python, by the way. So, here is a line of text in a file I am working with, for example: ">ref|ZP_01631227.1| 3-dehydroquinate synthase [Nodularia spumigena CCY9414]..." How can I extract the two strings "ZP_01631227.1" ...

C++ Convert string (or char*) to wstring (or wchar_t*)

string s = "おはよう"; wstring ws = FUNCTION(s, ws); How would i assign the contents of s to ws? Searched google and used some techniques but they can't assign the exact content. The content is distorted. ...

number out of string in java

I have something like "ali123hgj". i want to have 123 in integer. how can i make it in java? ...

Linked List Sorting with Strings In C

I have a struct, with a Name and a single Node called nextName It's a Singly Linked list, and my task is to create the list, based on alphabetical order of the strings. So iff i enter Joe Zolt and Arthur i should get my list structured as Joe Than Joe Zolt Than Arthur Joe Zolt I'm having trouble implementing the correct Algorit...

Ruby: Is there a way to split a string only with the first x occurrencies?

For example, suppose I have this: 001, "john doe", "male", 37, "programmer", "likes dogs, women, and is lazy" The problem is that the line is only supposed to have 6 fields. But if I separate it with split I get more, due to the comma being used improperly to separate the fields. Right now I'm splitting everything, then when I get to ...

Longest substring that appears n times

For a string of length L, I want to find the longest substring that appears n (n<L) or more times in ths string. For example, the longest substring that occurs 2 or more times in "BANANA" is "ANA", once starting from index 1, and once again starting from index 3. The substrings are allowed to overlap. In the string "FFFFFF", the longes...

Reading In A String and comparing it C

Im trying to create a C based string menu where a user inputs a command and then a block of code runs. Whatever i do the conditional is never true: char *input= ""; fgets(input, 50, stdin); printf("%s",input); printf("%d",strcmp( input,"arrive\0")); if(strcmp( input,"arrive\0")==0){.... Im fairly new to c and am finding strings reall...

Const unsigned char* to char*

So, I have two types at the moment: const unsigned char* unencrypted_data_char; string unencrypted_data; I'm attempting to perform a simple conversion of data from one to the other (string -> const unsigned char*) As a result, I have the following: strcpy((unencrypted_data_char),(unencrypted_data.c_str())); However, I'm receiving ...