This is probably a really stupid question...but how can I remove parts of a string up to a certain character?
Ex.) If I have the string testFile.txt.1 and testFile.txt.12345 how can I remove the 1 and 12345?
Thanks a lot for the help
How do I check if a String contains only letters in java? I want to write an if statement that will return false if there is a white space, a number, a symbol or anything else other than a-z A-Z. My string must contain ONLY letters.
I thought I could do it this way, but I'm doing it wrong:
if( ereg("[a-zA-Z]+", $myString))
return true;
else
return false;
Is there a way to get a report of how long each test is taking to run on a Ruby on Rails project? I have a a small set of tests, 2 or 3, which take about 50% of the time and I'd like to find out which ones are.
what am i doing wrong/what can i do??
import sys
import string
def remove(file):
punctuation = string.punctuation
for ch in file:
if len(ch) > 1:
print('error - ch is larger than 1 --| {0} |--'.format(ch))
if ch in punctuation:
ch = ' '
return ch
else:
return ch
ref = (open("ref.txt","r"))
test_file = (open("test.txt", "r"))
dictionary = ref.read().split()
file = test_file.read().lower()
file = remove(file)
print(file)
p.s, this is in Python 3.1.2
How can I replace a string with another string, within a given text file. Do I just loop through readline() and run the replacement while saving out to a new file? Or is there a better way?
I'm thinking that I could read the whole thing into memory, but I'm looking for a more elegant solution...
Thanks in advance
I want to know if my connection string is encrypted or not. I don't want to encrypt it again and again. This is only an issue in development stage. Any way to check the status of the connection string in App.config?
What would be the best way (ideally, simplest) to convert an int to a binary string representation in Java?
For example, say the int is 156. The binary string representation of this would be "10011100".
For the API (Android SDK API version 8) functions whose definitions list character sequence parameters, I can feed the function String instead. Best part is that they work the same way, no hassle, no warnings.
Is there a difference between the two types? And more importantly, is there an inherent danger if I send the function a String instead of a character sequence???
Thanks for any clarifications!!! :D
I'm looking for a function to convert a string to the xml string with xml entities where needed. Something like htmlentities in PHP but for XML and in Javascript.
Thank you for any help!
Hi ,
I have a string val = "14 22 33 48";
int matrix[5];
I need to insert each of the values in the string into the respective location in the array
Eg: matrix[0] = 14;
matrix[1] = 22;
matrix[2] = 33;
matrix[3] = 48;
How do I do this ?
If a string in Perl 5 passes looks_like_number, it might as well be a number. For instance,
my $s = "10" + 5;
results in $s being assigned 15.
Are there any cases where a string does not behave like it's numeric equivalent would have?
I want to sort one column fetched from mysql DB, and stored in an array. After fetching I am doing below steps.
1- DB Fetching fields array in row format.
->Field1, Field2, Field3, Field4, Field5
2- From that fields array One columns data [Field3], swapping string keywords.
eg. AB013, DB131, RS001
to->013AB, 131DB, 001RS
Now I want to sort above value in new string format
like-> 001RS, 013AB, 131DB
Is there a program out there or some other thing that will run some kind of virtualization for me or something, to test the hardware minimums for a program I write? Something I can do locally without install testing on, say, a 33 mhz 64kb ram IBM or something
I have a string "14 22 33 48". I need to insert each of the values in the string into the respective location in the array:
int matrix[5];
so that
matrix[0] = 14;
matrix[1] = 22;
matrix[2] = 33;
matrix[3] = 48;
How do I do this?
I did a little search on this but couldn't find anything useful.
The point being that if String value is either "true" or "false" the return value should be true. In every other value it should be false.
I tried these:
String value = "false";
System.out.println("test1: " + Boolean.parseBoolean(value));
System.out.println("test2: " + Boolean.valueOf(value));
System.out.println("test3: " + Boolean.getBoolean(value));
All functions returned false :(
There are many similar questions, but apparently no perfect match, that's why I'm asking.
I'd like to split a random string (e.g. 123xx456yy789) by a list of string delimiters (e.g. xx, yy) and include the delimiters in the result (here: 123, xx, 456, yy, 789).
Good performance is a nice bonus. Regex should be avoided, if possible.
Lot of questions has been already asked about the differences between string and string builder and most of the people suggest that string builder is faster than string. I am curious to know if string builder is too good so why string is there? Moreover, can some body give me an example where string will be more usefull than string builder?
I have a C++ string. I need to pass this string to a function accepting char* parameter,
for example - strchr().
a) How do I get that pointer?
b) Is there some funtion equivalent to strschr() that works for C++ strings?
Say you have a String literal with a lot of quotation marks inside it. You could escape them all, but it's a pain, and difficult to read.
In some languages, you can just do this:
foo = '"Hello, World"';
In Java, however, '' is used for chars, so you can't use it for Strings this way. Some languages have syntax to work around this. For example, in python, you can do this:
"""A pretty "convenient" string"""
Does Java have anything similar?
What classes do you use to make string placeholders work?
String template = "You have %1 tickets for %d",
Brr object = new Brr(template, {new Integer(1), new Date()});
object.print();
There are many similar questions, but apparently no perfect match, that's why I'm asking.
I'd like to split a random string (e.g. 123xx456yy789) by a list of string delimiters (e.g. xx, yy) and include the delimiters in the result (here: 123, xx, 456, yy, 789).
Good performance is a nice bonus. Regex should be avoided, if possible.
So I need to get value false or true if string contains not only letters of all european and east alphabets and " "(space) and "-" minus. How to do such thing with some $a string?
Hey,
many builtin classes in Java implement Iterable, however String does not. It makes sense to iterate over chars in the String, just as one can iterate over items in regular array. Is there a reason behind it?
I was working on a Magento module and it was working fine. At some point, I was trying to enable WYSIWYG in an edit form 'content' field and suddenly, my adminhtml grid and edit blocks stopped being generated. On my system are TinyMCE and Fontis FCKEditor WYSIWYG editors extensions. I'm not sure what I did wrong but my adminhtml blocks will no longer generate.
Here's a dump of all the blocks from my module's adminhtml layout:
array(17) {
[0]=>
string(4) "root"
[1]=>
string(4) "head"
[2]=>
string(13) "head.calendar"
[3]=>
string(14) "global_notices"
[4]=>
string(6) "header"
[5]=>
string(4) "menu"
[6]=>
string(11) "breadcrumbs"
[7]=>
string(7) "formkey"
[8]=>
string(12) "js_translate"
[9]=>
string(4) "left"
[10]=>
string(7) "content"
[11]=>
string(8) "messages"
[12]=>
string(2) "js"
[13]=>
string(6) "footer"
[14]=>
string(8) "profiler"
[15]=>
string(15) "before_body_end"
[16]=>
string(7) "wysiwyg"
}
As you can see, the last item is "wysiwyg" but on the layout output of other magento modules, there are more blocks. For example, on MathieuF's calendar extension, these are all the layout blocks:
array(26) {
[0]=>
string(4) "root"
[1]=>
string(4) "head"
[2]=>
string(13) "head.calendar"
[3]=>
string(14) "global_notices"
[4]=>
string(6) "header"
[5]=>
string(4) "menu"
[6]=>
string(11) "breadcrumbs"
[7]=>
string(7) "formkey"
[8]=>
string(12) "js_translate"
[9]=>
string(4) "left"
[10]=>
string(7) "content"
[11]=>
string(8) "messages"
[12]=>
string(2) "js"
[13]=>
string(6) "footer"
[14]=>
string(8) "profiler"
[15]=>
string(15) "before_body_end"
[16]=>
string(7) "wysiwyg"
[17]=>
string(27) "adminhtml_event.grid.child0"
[18]=>
string(12) "ANONYMOUS_19"
[19]=>
string(27) "adminhtml_event.grid.child1"
[20]=>
string(12) "ANONYMOUS_21"
[21]=>
string(27) "adminhtml_event.grid.child2"
[22]=>
string(20) "adminhtml_event.grid"
[23]=>
string(12) "ANONYMOUS_24"
[24]=>
string(19) "ANONYMOUS_17.child1"
[25]=>
string(14) "content.child0"
}
Does anyone have any idea what's wrong? I've already tried Alan Storm's Layout and Config Viewers and cannot find any clues as to what I did wrong. Any help would be greatly appreciated.