string

Why does this C++ program print irrelevant characters?

Hey i am new to programming in C++, and i get the hang of it but i got stuck on this one simple problem i am suppose to create a shift cipher using the letters A-Z and shifting them 3 places, i get everything but when i do my output i get extra letters that are unneeded like "|[|" i know i have to put a terminator and i did but doesn't s...

vbscript return string of whole words <=specified limit

I want to, in vbScript (Classic ASP), parse a string to a specified length without cutting words. The final string may be less than the specified length (to avoid cutting words), but should not exceed it.. ...

How can a string be validated in Java?

How can a string be validated in Java? I.e. only characters are allowed and not numbers? How about email validation? ...

Howto Format dict string outputs nicely

I wonder if there is an easy way to format Strings of dict-outputs such as this: { 'planet' : { 'name' : 'Earth', 'has' : { 'plants' : 'yes', 'animals' : 'yes', 'cryptonite' : 'no' } } } ..., where a simple str(dict) just would give you a quite unreadable ... {'planet' : {'has': {'plants': 'yes', 'an...

How to return a char array created in function?

Hello, I've been programming badly for quite a while and I only really just realised. I have previously created many functions that return character strings as char arrays (or at least pointers to them). The other day someone pointed out that when my functions return the char arrays pointed to by my functions have gone out of scope and...

Seach inside a string

$variable = 'of course it is unnecessary [http://google.com], but it is simple["very simple"], and this simple question clearly needs a simple, understandable answer [(where is it?)] in plain English' Value of this variable everytime changes. What I trying to do is to get the text from [...]. So, if there is [(google)], the match sho...

In Perl, how can I print lines read from a file with optional leading whitespace removed?

#!/usr/bin/perl open(SARAN,"first.txt") or die "Can't Open: $!\n"; while($line=<SARAN>) { print "$line\n"; } close SARAN; Hi, In the above perl script, i need one functionality... in first.txt, each line starts with some space in front.. I need to print the lines without space in front... What to do. thanks.. ...

Why does this program give segmentation fault?

Hi, It's a beginners question: Why is this breaking/giving an error? #include <stdio.h> #include <stdlib.h> #include <string.h> char *strtrim_right(char *p) { char *end; int len; len = strlen( p); while (*p && len) { end = p + len-1; if(isalpha(*end)) *end =0; else break; } return(p);...

How do I combine all elements in an array using comma?

Hey I know this question has with out any doubt been asked a whole lot of times. I though can seem to find a solution. So forgive me if it's way to simple. The question is how do access the end of a while loop. E.g. while($countByMonth = mysql_fetch_array($countByMonthSet)) { $c = $countByMonth["COUNT(id)"]; ...

How can I parse two subjects from a string?

This is fairly difficult to explain. I am working on a text adventure at the moment and I am parsing input from a player. When a player enters input, there can be two possible subjects (let's call them subject1 and subject2). For example, in the following: "hit door with stick", subject1 is "door" and subject2 is "stick". In this case,...

C# - Getting the folder name from a path

Hi Here is some code string path = "C:/folder1/folder2/file.txt"; What objects or methods could I use that would give me a result of folder2? Thank you in advance. ...

Matching a few letters and letters with numbers

I'm trying to match letters C D F H I E1 E2 CR (case insensitive) and came up with this. It'll match a single letter but wont match the E1 E2 CR. Actually it should. Whats the right way to do this? preg_match('/^([C]|[D]|[F]|[H]|[I]|[E1]|[E2]|[CR]?)$/','CR') ...

Adding keys to a list or collection - is there any value in hashing the key before adding it

I have stumbled across some code that is adding strings to a List but hashing the value before adding it. It's using an MD5 hash (MD5CryptoServiceProvider) on the string value, then adding this to the list. Is there any value in doing this in terms of speed to find the key in the list or is this just unnecessary? ...

converting String.data() into an array

Hi, I want to take a string,and populate an array with its values. I know the length of the string is 16. I have tried char *bit_number[16]; bit_number = bin.data(); and char bit_number[16]; bit_number = bin.data(); I don't understand what String.data() is returning, why can't I assign it directly to an array? I'm getting compiler ...

Extra numbers being appended to string, don't know why??

Number(string binary) { int raw_string_int[size]; char raw_string_char[size]; strcpy(raw_string_char,binary.c_str()); printf("Raw String is %s",raw_string_char); for (int i=0;i<size;i++) { raw_string_int[i] = int(raw_string_char[...

Efficient memory storage and retrieval of categorized string literals in C++

Note: This is a follow up to this question. I have a "legacy" program which does hundreds of string matches against big chunks of HTML. For example if the HTML matches 1 of 20+ strings, do something. If it matches 1 of 4 other strings, do something else. There are 50-100 groups of these strings to match against these chunks of HTML (usu...

Binary Numbers. Error When Checking to be sure binary input is binary...

I'm writing a simple loop to make sure my input is a valid binary. Ex: I want to throw an error when any number higher than one is user input. I know I need to check against the ASCII numbers. What is going on here? I should not be getting an error when I input binary. Any thoughts? for (int i=0;i<size;i++) { printf("%i is string su...

PHP Shorthand for Pre-Concatenation?

I've been programming in PHP for years, and I've always wondered if there is a way to 'pre-concatenate' a string. Example: $path = '/lib/modules/something.php'; $server = $_SERVER['DOCUMENT_ROOT']; I've been doing this for years in order to append a value to the beginning of a string: $path = $server . $path; // returns: /home/somesi...

Best way to pass string to function ?

What's the best way from security perspective to pass string to a function. I know I can use globals, session and in function string. Like function test($string). What's the best approach ? If any one knows please let me know. I'm trying to write something like this for example: $url = 'http://domain.com/'; function test() { echo $u...

How can I searching for different variants of bioinformatics motifs in string, using Perl?

I have a program output with one tandem repeat in different variants. Is it possible to search (in a string) for the motif and to tell the program to find all variants with maximum "3" mismatches/insertions/deletions? ...