I've got a string with a bunch of multi-letter codes in it and I'd like to parse it out according to those codes. I'm not sure how to make it look at more than one character to determine if it forms part of a code.
My string looks like this:
BBCTEEBOBBB
and I want to parse out these instances:
E
BB
CT
BOB
So the result should be out...
I'm trying to read input from the terminal. For this, I'm using a BufferedReader. Here's my code.
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String[] args;
do {
System.out.println(stateManager.currentState().toString());
System.out.print("> ");
args = reader.readLine().split(" ");
// us...
I like how i can do string [] stringArray = sz.split('.');
but is there a way to merge them back together? (stringArray.Merge(".");)
...
In PHP I can do this:
$new = str_replace(array('/', ':', '.'), '', $new);
...to replace all instances of the characters / : . with a blank string (to remove them)
Can I do this easily in Objective-C? Or do I have to roll my own?
Currently I am doing multiple calls to stringByReplacingOccurrencesOfString:
strNew = [strNew stringByRe...
If I have numbers as a text string without decimal places, how can I convert it to 2 decimal places such that 12345 is converted to 123.45? The string can be any length greater than 1.
...
Does anyone know how to do convert from a string to a boolean in Python? I found this link. But it doesn't look like a proper way to do it. I.e. using a built in functionality, etc.
EDIT: The reason I asked this is because I learned int("string"), from here. I tried bool ("string") but always got True.
...
The following...
require 'yaml'
test = "I'm a b&d string"
File.open('test.yaml', 'w') do |out|
out.write(test.to_yaml)
end
...outputs ...
--- this is a b&d string
How can I get it to output
--- 'this is a b&d string'
???
...
I am reading data from a file like this
while (<$fh>)
{
@tmp = split; # <-- ?
push @AoA, [@tmp];
}
I have a couple of questions regarding this. What does the marked line do? Does it split the file by lines and store elements of each line into an array?? If so, is it possible to convert @tmp into a string or do a regex...
I have a daemon that reads a configuration file in order to know where to write something. In the configuration file, a line like this exists:
output = /tmp/foo/%d/%s/output
Or, it may look like this:
output = /tmp/foo/%s/output/%d
... or simply like this:
output = /tmp/foo/%s/output
... or finally:
output = /tmp/output
I hav...
$split_point = ' - ';
$string = 'this is my - string - and more';
How can i make a split using the second instance of $split_point and not the first one. Can I specify somehow a right to left search? Best simple approach?
Basically how do I explode from Right to Left. I want to pick up the last instance of " - ".
Result I need:
$ite...
I'm wondering if string.Length in C# is an instant variable. By instant variable I mean, when I create the string:
string A = "";
A = "Som Boh";
Is length being computed now?
OR
Is it computed only after I try to get A.Length?
...
I'm sorry, didn't know that Length is computed at construction time!!
I got 200 char long string A, 5 char long string B
If I do
int Al = A.length;
int Bl = B.length;
and compare it -- all seems fine BUT If I do this few million times to
calculate something, it's too expensive for the thing I need.
Much simpler and neater way wou...
Hi,
Does anyone know why C# (.NET)'s StartsWith function is considerably slower than IsPrefix?
...
Hi,
I'm doing some calculations of comparing two strings. In case I know they are same length, is it more expensive to call isprefix or If ("string"=="string") ?
...
I have a function isNotEmpty which returns true if the string is not empty and false if the string is empty. I've found out that it is not working if I pass an empty string through it.
function isNotEmpty($input)
{
$strTemp = $input;
$strTemp = trim($strTemp);
if(strTemp != '') //Also tried this "if(strlen($strTemp) > 0)"...
I'm trying to convert a string to a double value but it's not returning me what I expect...
double dbl;
Double.TryParse("20.0", out dbl);
That piece of code is returning 200.0 (instead of 20.0) as a double value. Any idea why?
...
char hello[] = "hello"; #C
hello = ['h', 'e', 'l', 'l', 'o'] #Ruby
If I output the class of hello[0] in Ruby, it says "String". This is because single quoted Strings exist in Ruby and there does not seem to be the notion of a char type. The other day I said to my coworker that he had an array of characters and he said "no I don't, I ha...
Hi all,
I have a vector of string and I intend to join these strings into a single string, separated by a space. For example, if my vector contains the values:
sample
string
for
this
example
I want the output to be "sample string for this example".
Need any of your input on what is the simplest way of achieving this?
Thanks
...
Given a byte array (byte[]) is there any quick (as in short and aesthetic) way of transforming this into a string och character array? Assume that the bytes in the array is text represented in ascii.
I'm working in c# right now, and can't find any obvious methods to use. But I'm also interested in a general solution applicable to any m...
BASE_URL = 'http://foobar.com?foo=%s'
variable = 'bar'
final_url = BASE_URL % (variable)
I get this 'http://foobar.com?foo=bar' # It ignores the inside string.
But i wanted something like this 'http://foobar.com?foo='bar''
Thanks for the answer.
Can you help me out with almost the same problem:
lst = ['foo', 'bar', 'foo bar']
[s...