string

Java FileOutputStream String Writing

I’ve been having issues with a Java File. Its designed to write line after line in a test file as a log. Unfortunately it overwrites the same line every time I call it. If anyone can help I would be eternally grateful as this has been driving me up the wall! Code Below. Thanks. public abstract class Log { protected static String Def...

visual basic to c string literals "\\.\" and "\"

In visual basic I have the following 2 strings: "\\.\" & "\" How do I represent them in C? Also, & in VB is the concatenation operator? ...

Ruby - How to unpack a binary string into a normal string?

I'm opening a CSV file and reading values from it using File.open(filename). So I do something like this: my_file = File.open(filename) my_file.each_line do |line| line_array = line.split("\t") ratio = line_array[1] puts "#{ratio}" puts ratio.isutf8? end The issue I'm having is the values in line_array seem to be in a strange for...

Check if string contains a range of numbers

I'd like to test a std::string for containing numbers of any range e.g 5 to 35 in a std::string s = "XDGHYH20YFYFFY" would there be function or I would have to convert a number to string and then use a loop to find each one? ...

Why doesn't strerror return a const-qualified pointer?

I was just skimming the C99 standard, looking for something that I don't remeber now, when I noticed that the pointer returned from the strerror function (section 7.12.6.2) isn't const-qualified, even though the standard says: The strerror function returns a pointer to the string, the contents of which are locale-specific. The arra...

Python string formatter for paragraphs

I'm trying to format some strings for output on the command-line, report style, and am looking for the easiest method to format a string such that I can get automatic paragraph formatting. In perlform formatting is done through the "format" function format Something = Test: @<<<<<<<< @||||| @>>>>> $str, $%, '$' ....

Java: Finding how many words appear in BOTH data sources?

Hi! I'm trying to figure out if there is an easy way to count the number of words that appear in small paragraph (#1) and small paragraph (#2). Generally, Im determining how much overlap there is in these paragraphs on a word by word basis. So if (#1) contains the word "happy" and (#2) contains the word "happy" that would be like a +1...

JavaScript associative array by variable

I'd like to pass a variable into the key of my monthHash variable here: var monthHash = new Array(); monthHash["JAN"] = "Jan"; monthHash["FEB"] = "Feb"; ... monthHash["NOV"] = "Nov"; monthHash["DEV"] = "Dec"; Such that I can do this: alert(monthHash[the_variable]); Instead of using a switch case to go through this. When...

how to set string character encoding in android

HI! I have a web page content in encoded in ISO-8859-2. How to convert a stream encoded in this charset to java's UTF-8. I'm trying the code below, but it does not work. It messes up some characters. Is there some other way to do this? BufferedInputStream inp = new BufferedInputStream(in); byte[] buffer = new byte[8192]; int...

How to find the no of elements in an string array (the string is passed to a function).

#include<iostream> #include<string> using namespace std; class Prerequisites { public: void orderClasses(string* Input); }; void Prerequisites::orderClasses(string* Input) { // Need to find the length of the array Input } int main() { Prerequisites A; string classes[]={"CSE121: CSE110", "CSE110:"...

Haskell Custom Remove WhiteSpace

Hello to all, i have a and i would like to remove the white Space after "\n" and next character is white space. For instance, "username 123\n ugas 423\n peter 23\n asd234" become "username 123\nugas 423\npeter 23\nasd234" Please help. Thanks. ...

Java equivalent of python's String lstrip()?

I'd like to remove the leading whitespace in a string, but without removing the trailing whitespace - so trim() won't work. In python I use lstrip(), but I'm not sure if there's an equivalent in Java. As an example " foobar " should become "foobar " I'd also like to avoid using Regex if at all possible. Is there a built...

changing CharSequence first letter to upper case in android

it may seem simple but it posses lots of bugs I tried this way: String s = gameList[0].toString(); s.replaceFirst(String.valueOf(s.charAt(0)),String.valueOf(Character.toUpperCase(s.charAt(0))) ); and it throws an exception another try i had was : String s = gameList[0].toString(); char c = Character.toUpperCase(gameList[0].charA...

Remove end of line characters from end of Java String

I have a string which I'd like to remove the end of line characters from the very end of the string only using Java "foo\r\nbar\r\nhello\r\nworld\r\n" which I'd like to become "foo\r\nbar\r\nhello\r\nworld" (This question is similar to, but not the same as question 593671) ...

How to pad all the numbers in a string.

I've got lots of address style strings and I want to sort them in a rational way. I'm looking to pad all the numbers in a string so that: "Flat 12A High Rise" becomes "Flat 00012A High Rise", there may be multiple numbers in the string. So far I've got: def pad_numbers_in_string(string, padding=5): numbers = re.findall("\d+", stri...

How to compress a string in .net c# and decompress it in flash as3?

Hi, I have to load a large xml in flash and I'm trying to send it compressed. To do that I tried to zlib compress the string and send it base64 encoded. In flash I turn the string into a byte array and use its uncompress() method. So far I tried: ZLIB.NET byte[] bytData = System.Text.Encoding.UTF8.GetBytes(str); MemoryStream ms = new ...

How should I concatenate strings?

Are there differences between these examples? Which should I use in which case? var str1 = "abc" + dynamicString + dynamicString2; var str2 = String.Format("abc{0}{1}", dynamicString, dynamicString2); var str3 = new StringBuilder("abc").Append(dynamicString).Append(dynamicString2).ToString(); var str4 = String.Concat("abc", dynamicS...

How can i get 0 infront of any number?

Hi guys, I would like to append 0 before a number if it is single digit. ie. it should be 01,02,03... 09, 10, 11, ... and so on I am using vb.net... how can i do that? Edit: It was really nice to c alot of responses... I am thankful to you all for help. your suggestions worked correctly but i can choose only one correct answer so n...

Stripping texts in a variable : javascript

Hello, Consider variable like var url='http://www.example.com/index.php?id=ss'; or var url='http://www.example.com/dir1/dir2/index.php'; In these variables, i want to get only the domain part i.e http://www.example.com, stripping out other texts. Is this possible in ordinary javascript or jquery ? Please help ...

Use latin characters in appengine

How can store latin characters in appengine? (e.g. "peña") when I want to store this I get this error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xf1 in position 2: ordinal not in range(128) I can change the Ñ by N, but, there not another and better way? And if i encode the value, how can print "Peña" again? ...