string

How do you echo a string with every char in PHP?

I need to know if there's a way in PHP to echo a string with every char. For instance /n and the likes. Edit for clarification: When I have a webform and I submit it and I have this text: I am stupid and I cannot explain myself The text would be like this: I am stupid /n and I cannot /n explain myself If I use: nl2br I g...

EF4 LINQ Include(string) alternative to hard-coded string?

Is there any alternative to this: Organizations.Include("Assets").Where(o => o.Id == id).Single() I would like to see something like: Organizations.Include(o => o.Assets).Where(o => o.Id == id).Single() to avoid the hard-coded string "Assets". ...

Need help in Hashtable implementation

Hi all, i'm quite a beginner in C# , i tried to write a program that extract words from an entered string, the user has to enter a minimum length for the word to filter the words output ... my code doesn't look good or intuitive, i used two arrays countStr to store words , countArr to store word length corresponding to each word .. but t...

C String input confusion

C really isn't my strong point and after reading 3 chapters of a book on the subject and spending ages trying to get stuff working it just doesn't: #include <stdio.h> char *a,*b; int main( ) { char input[10]; fgets(input,sizeof input, stdin); a = input; fgets(input,sizeof input, stdin); b = input; printf("%...

Java strings and substrings

hey folks, Can someone help me with this Java problem? I want to write a method that takes two strings as arguments and returns true if each character (including space and punctuation) that appears in one string also appears in the other. Thanks ...

Why does this code read all ' ' for the anything after the 4th character?

#define fileSize 100000 int main(int argc, char *argv[]){ char *name=argv[1]; char ret[fileSize]; FILE *fl = fopen(name, "rb"); fseek(fl, 0, SEEK_END); long len = fileSize; fseek(fl, 0, SEEK_SET); //fread(ret, 1, len, fl); int i; *(ret+fileSize) = '\0'; ...

String unique characters

Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures? ...

In Ruby language, how can I get the number of lines in a string?

Hi guys, In Ruby language, how can I get the number of lines in a string? ...

how to find whether a string in a another string..

a='1234;5' print a.index('s') thr error is : > "D:\Python25\pythonw.exe" "D:\zjm_code\kml\a.py" Traceback (most recent call last): File "D:\zjm_code\kml\a.py", line 4, in <module> print a.index('s') ValueError: substring not found thanks ...

URLEncoding a string with Objective-C

I'm trying to URL encode a string to form a GET request from objective-c. NSString *params = @"'Decoded data!'/foo.bar:baz"; NSRunAlertPanel( @"Error", [params urlEncoded], @"OK", nil, nil ); This is the category extending NSString -(NSString *) urlEncoded { NSString *encoded = (NSString *)CFURLCreateStringByAddingPercentEsc...

Parsing multibyte string in PHP

I would like to write a (HTML) parser based on state machine but I have doubts how to acctually read/use an input. I decided to load the whole input into one string and then work with it as with an array and hold its index as current parsing position. There would be no problems with single-byte encoding, but in multi-byte encoding each ...

NSString - Unicode to ASCII equivalent

Hello, I need to convert NSString in unicode to NSString in ASCII changing all local characters: Ą to A, Ś to S, Ó to O, ü to u, And do on... What is the simplest way to do it? ...

Python: Converting a tuple to a string

Given this : import os import subprocess def check_server(): cl = subprocess.Popen(["nmap","10.7.1.71"], stdout=subprocess.PIPE) result = cl.communicate() print result check_server() check_server() returns this tuple: ('\nStarting Nmap 4.53 ( http://insecure.org ) at 2010-04-07 07:26 EDT\nInteresting ports on 10.7.1....

Extracting URLs (to array) in Ruby

Good afternoon, I'm learning about using RegEx's in Ruby, and have hit a point where I need some assistance. I am trying to extract 0 to many URLs from a string. This is the code I'm using: sStrings = ["hello world: http://www.google.com", "There is only one url in this string http://yahoo.com . Did you get that?", "The first URL in t...

How should I write this string-prefix check so that it's idiomatic Python?

I have a couple of lists of items: specials = ['apple', 'banana', 'cherry', ...] smoothies = ['banana-apple', 'mocha mango', ...] I want to make a new list, special_smoothies, consisting of elements in smoothies that start with the elements in specials. However, if specials is blank, special_smoothies should be identical to smoothies...

Removing non-breaking spaces from strings using Python

Hello: I am having some trouble with a very basic string issue in Python (that I can't figure out). Basically, I am trying to do the following: '# read file into a string myString = file.read() '# Attempt to remove non breaking spaces myString = myString.replace("\u00A0"," ") '# however, when I print my string to output to consol...

C: evaluate part of the string

I cant find an expression to evaluate a part of a string. I want to get something like that: if (string[4:8]=='abc') {...} I started writing like this: if (string[4]=='a' && string[5]=='b' && string[6]=='c') {...} but if i need to evaluate a big part of string like if (string[10:40] == another_string) {...} then it gets to wri...

Write string to fixed-length byte array in C#

somehow couldn't find this with a google search, but I feel like it has to be simple...I need to convert a string to a fixed-length byte array, e.g. write "asdf" to a byte[20] array. the data is being sent over the network to a c++ app that expects a fixed-length field, and it works fine if I use a BinaryWriter and write the characters o...

checking last char of string in c

If I have two types of strings as: const char *str1 = "This is a string with \"quotes escaped at the end\""; const char *str2 = "This is a \"string\" without quotes at the end"; testFn(str1); testFn(str2); int testFn(const char *str) { // test & return 1 if ends on no quote // test & return 0 if ends on quote return; } I wo...

Question about memory allocation when initializing char arrays in C/C++.

Before anything, I apologize if this question has been asked before. I am programming a simple packet sniffer for a class project. For a little while, I ran into the issue where the source and destination of a packet appeared to be the same. For example, the source and destination of an Ethernet frame would be the same MAC address all o...