string

Variable interpolation in Python

Possible Duplicate: Unpythonic way of printing variables in Python? In PHP one can write: $fruit = 'Pear'; print("Hey, $fruit!"); But in Python it's: fruit = 'Pear' print("Hey, {0}!".format(fruit)) Is there a way for me to interpolate variables in strings instead? And if not, how is this more pythonic? Bonus points for ...

Subscript and Superscript a String in Java

How can you print a string with a subscript or superscript? Can you do this without an external library? I want this to display in a TextView in Android. ...

Accessing the name of an instance in Python (so I can print it)

So as part of problem 17.6 in "Think Like a Computer Scientist", I've written a class called Kangaroo: class Kangaroo(object): def __init__(self, pouch_contents = []): self.pouch_contents = pouch_contents def __str__(self): ''' >>> kanga = Kangaroo() >>> kanga.put_in_pouch('olfactory') >...

skipping vector position when pushing_back

Hi there, I'm reading data from a file into a vector of strings called data. And to this data vector I push_back a new string through my main called output_string. Output_string is just a combination of the arguments passed in through command line. After doing all that I write back to my file(update the file with the new string). However...

Java: how to check that a string is parsable to a double?

Is there a native way (preferably without implementing your own method) to check that a string is parsable with Double.parseDouble()? ...

Counting unique words in a file? Good Linear Search alternative?

I'm using a naive approach to this problem, I'm putting the words in a linked list and just making a linear search into it. But it's taking too much time in large files. I was thinking in use a Binary Search Tree but I don't know if it works good with strings. Also heard of Skip Lists, didn't really learn it yet. And also I have to use...

How can i get the numerical value (convert it to int) from a string?

I only see strings with only numbers. this is my string. SMUL 9 A B How can I get the number 9 as int type. Other possible string may be: SMUL 13 A B SMUL 43 100 21 ...

How can I split strings into different types (int for numerical values and char for letters)?

For example, I have this string: SMUL 9 A B? How can I get 9 (int type) A (char) and B (char). Possible string may be SMUL 12 A C, so it means their positions in the string is not constant. Further explanation: this is a string inputted by a user for my matrix calculator program. Inputting SMUL "scalar" "matrix-1" "matrix-2" means that ...

ASP.NET MVC string formatting c# - show 20 characters of 100 - trim/cut string

Hello all, I have a small trouble. I want to show just a part of a string for example: Instead: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua." Just a: "Lorem ipsum dolor sit amet, consetetur sadipscing..." Which method can ...

ASP.NET MVC string formatting c# - by 100 characters make 4 rows each 25 characters

I have a string with 100 characters and it is for me too long in one line. I want to make NewLine after each 25 characters. For example: Instead: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua." Just a: "Lorem ipsum dolor sit ...

Java String Concatenation

I have a issue with my java code. i asked the same question yesterday. I got answer but sorry it was my fault. My question is not clear. I have code looks like this: for(i = 0; i < geo.getTargets().length ; i++ ) { if(geo.getTargets(i).getTargetType().equalsIgnoreCase("ProximityTarget")) { final Proxim...

C memcpy error - memory could not be written on Windows XP

I have a C program which loads a file line-by-line into one string and then memcpy's this string into another string pointer using this code: typedef struct inmod_struct { Int32 ReturnCode; Int32 Length; char Body[ROWSIZE]; } inmdtyp,*inmdptr; inmdptr inmodptr; char line[600]; int doit() { ...

Can I redefine String#length?

I'd like to re-implement a method of a Java class. For example, for "hi".length() to return 4. (How) Can I do that? I know using SomeClass.metaClass I can get a reference to an existing method and define new (or overriding) method, but I can't seem to be able to do that for existing Java methods. ...

Treat unicode character plus diacritic as a single character?

In my VB.NET application I compare words that are recorded using IPA, many of which have many diacritic marks. In one of the comparisons, I compare the words character by character. But when I iterate over the characters, the diacritic marks come out as separate characters (as I would expect since this is unicode): o`ku`ku` However,...

How to extract the first word that follows a string?

For example, say I have a text file example.txt that reads: I like dogs. My favorite dog is George because he is my dog. George is a nice dog. Now how do I extract "George" given that it is the first word that follows "My favorite dog is"? What if there as more than one space, e.g. My favorite dog is George ..... Is there a wa...

how to substitute part of a string in python?

How to replace a set of characters inside another string in Python? Here is what I'm trying to do: let's say I have a string 'abcdefghijkl' and want to replace the 2-d from the end symbol (k) with A. I'm getting an error: >>> aa = 'abcdefghijkl' >>> print aa[-2] k >>> aa[-2]='A' Traceback (most recent call last): File "<pyshell#2>",...

how to 'marry' two strings in python?

What would be a smart way to mix two strings in python? I need something to insert one string into another one with specified (default=1) intervals: >>> aa = 'abcdefghijkl' >>> bb = mix(aa) >>> bb 'a b c d e f g h i j k l ' >>> cc = mix(bb,'\n',8) >>> print cc a b c d e f g h i j k l Is there an elegant way to write the 'mix' code...

What is the fastest way to parse text?

Say I want to extract the first word (or floating point number) that follows a given string found in some text file (see http://stackoverflow.com/questions/3549877/how-to-extract-the-first-word-that-follows-a-string). I know you can do it with perl, or sed, and probably many other ways. I am looking for performance. What is the fastest w...

Any way to use multiple encryptions on one string without doubling or expanding the size of the output string?

My input string suppose is: 256 Bytes Ascii text. Let's assume I encrypted it with an encryption algo. But when I re-encrypt the same encrypted result string which was output of the first encryption, the size of the second result string from the second encryption from the same encryption algo increases, even doubles! Dear friends! Is th...

Fortran string comparison with .LT.

Hello Group, I have to fix a bug in a very old and large financial system that uses Fortran, C and C++. I am primarily a C++ guy, have no idea abt Fortran! I have a problem understanding a Fortran statement which i think has caused a nasty bug in our systems.... if (instructions .lt. ' ') then instructions = ' ' endif instructio...