How can I replace this "a b" by "a b" in j2me?
the replace() method doesn't accept Strings, but only chars. And since a double space contains two chars, I think i have a small problem.
I'm new to Ruby, and have been working my way through Mr Neighborly's Humble Little Ruby Guide. There have been a few typos in the code examples along the way, but I've always managed to work out what's wrong and subsequently fix it - until now!
This is really basic, but I can't get the following example to work on Mac OS X (Snow Leopard):
gone = "Got gone fool!"
puts "Original: " + gone
gone.delete!("o", "r-v")
puts "deleted: " + gone
Output I'm expecting is:
Original: Got gone fool!
deleted: G gne fl!
Output I actually get is:
Original: Got gone fool!
deleted: Got gone fool!
The delete! method doesn't seem to have had any effect.
Can anyone shed any light on what's going wrong here? :-\
I can't figure out what to do to make this work. Here's my code:
char* testStr = " trim this ";
char** pTestStr = &testStr;
trim(pTestStr);
int trim(char** pStr)
{
char* str = *pStr;
while(isspace(*str)) {
(*pStr)++;
str++;
}
if(*str == 0) {
return 0;
}
char *end = str + strlen(str) - 1;
while(end > str && isspace(*end))
end--;
*(end+1) = 0;
return 0;
}
I get an access violation on *(end+1) = 0;, but I can't declare my testStr[] as such to avoid that, because I can't pass the pointers that way. Any ideas?
I have a distance as a float and I'm looking for a way to format it nicely for human readers. Ideally, I'd like it to change from m to km as it gets bigger, and to round the number nicely. Converting to miles would be a bonus. I'm sure many people have had a need for one of these and I'm hoping that there's some code floating around somewhere.
Here's how I'd like the formats:
0-100m: 47m (as a whole number)
100-1000m: 325m or 320m (round to the nearest 5 or 10 meters)
1000-10000m: 1.2km (round to nearest with one decimal place)
10000m +: 21km
If there's no code available, how can I write my own formatter?
Thanks
I'm working with the fulltext search engine of MSSQL 2008 which expects a search string like this:
("keyword1" AND "keyword2*" OR "keyword3")
My users are entering things like this:
engine 2009
"san francisco" hotel december xyz
stuff* "in miami" 1234
something or "something else"
I'm trying to transform these into fulltext engine compatible strings like these:
("engine" AND "2009")
("san francisco" AND "hotel" AND "december" AND "xyz")
("stuff*" "in miami" "1234")
("something" OR "something else")
I have a really difficult time with this, tried doing it using counting quotation marks, spaces and inserting etc. but my code looks like horrible for-and-if vomit.
Can someone help?
I need to split some info from a asterisk delimitted data.
Data Format:
NAME*ADRESS LINE1*ADDRESS LINE2
Rules:
1. Name should be always present
2. Address Line 1 and 2 might not be
3. There should be always three asterisks.
Samples:
MR JONES A ORTEGA*ADDRESS 1*ADDRESS2*
Name: MR JONES A ORTEGA
Address Line1: ADDRESS 1
Address Line2: ADDRESS 2
A PAUL*ADDR1**
Name: A PAUL
Address Line1: ADDR1
Address Line2: Not Given
My algo is:
1. Iterate through the characters in the line
2. Store all chars in a temp variables until first * is found. Reject the data if no char is found before first occurence of asterisk. If some chars found, use it as the name.
3. Same as step 2 for finding address line 1 and 2 except that this won't reject the data if no char is found
My algo looks ugly. The code looks uglier. Spliting using //* doesn't work either since name can be replaced with address line 1 If the data is *Address 1*Address2, split will create two indexes in the array where index 0 will have the value of Address 1 and index 2 will have the value of Address2. Where's the name. Was there a name? Any suggestion?
Hi,
Could you please have a look at my code below.
#!C:\Perl\bin\perl.exe
use strict;
use warnings;
use Data::Dumper;
my $fh = \*DATA;
my $str1 = "listBox1.Items.Add(\"";
my $str2 = "\")\;";
while(my $line = <$fh>)
{
$line=~s/^\s+//g;
print $str1.$line.$str2;
chomp($line);
}
__DATA__
Hello
World
Output:
D:\learning\perl>test.pl
listBox1.Items.Add("Hello
");listBox1.Items.Add("World
");
D:\learning\perl>
Style error. I want the style below. Is ther anything wrong about my code? thanks.
D:\learning\perl>test.pl
listBox1.Items.Add("Hello");
listBox1.Items.Add("World");
D:\learning\perl>
Hi,
I'm trying to shorten a wordpress title to just the first word. For a page named "John Doe" I want to have a sub title somewhere on the page that says "About John" so I want to just get the first word from the title.
Is there a way to do this with PHP?
Thanks!
have funciton in my object which is called regularly.
parse : function(html)
{
var regexp = /...some pattern.../
var match = regexp.exec(html);
while (match != null)
{
...
match = regexp.exec(html);
}
...
var r = /...pattern.../g;
var m = r.exec(html);
}
with unchanged html the m returns null each other call. let's say
parse(html);// ok
parse(html);// m is null!!!
parse(html);// ok
parse(html);// m is null!!!
// ...and so on...
is there any index or somrthing that has to be reset on html ... I'm really confused. Why match always returns proper result?
I need to split some info from a asterisk delimitted data.
Data Format:
NAME*ADRESS LINE1*ADDRESS LINE2
Rules:
1. Name should be always present
2. Address Line 1 and 2 might not be
3. There should be always three asterisks.
Samples:
MR JONES A ORTEGA*ADDRESS 1*ADDRESS2*
Name: MR JONES A ORTEGA
Address Line1: ADDRESS 1
Address Line2: ADDRESS 2
A PAUL*ADDR1**
Name: A PAUL
Address Line1: ADDR1
Address Line2: Not Given
My algo is:
1. Iterate through the characters in the line
2. Store all chars in a temp variables until first * is found. Reject the data if no char is found before first occurence of asterisk. If some chars found, use it as the name.
3. Same as step 2 for finding address line 1 and 2 except that this won't reject the data if no char is found
My algo looks ugly. The code looks uglier. Spliting using //* doesn't work either since name can be replaced with address line 1 if the data was *Address 1*Address2. Any suggestion?
Hi all,
I'm new to pgf so i was trying out some examples from the pgfplot manual. One example is especially relevant for my current task but, alas, it would not compile.
Here is the code:
\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[symbolic x coords={a,b,c,d,e,f,g,h,i}]
\addplot+[smooth] coordinates {
(a,42)
(b,50)
(c,80)
(f,60)
(g,62)
(i,90)};
\end{axis}
\end{tikzpicture}
\end{document}
the compiler quits with the following error:
! Package PGF Math Error: Could not parse input 'a' as a floating point number,
sorry. The unreadable part was near 'a'..
I have no clue how to correct this behavior. Other plots (smooth, scatter, bar), which contain only numerical data compile fine.
Could anybody give me a hint?
Cheers
K.
CodeSmith has a nice StringUtils class that can be used to change database object names to singular, plural, camel case, pascal case, etc... Very useful for creating data access layers in their code generation tool.
I'm trying to port some CodeSmith templates to the T4 template files used by Visual Studio, and I'm trying to find a similar library to do these things.
There must be one somewhere in T4, since that's what is used to produce the LINQ to SQL classes, and it does a nice job of pluralization / singularization.
Does anyone know where this library exists, or if a free library with similar functionality exists somewhere?
Thanks!
Write your own version of the strcmp function string_compare.
Supply a main program that will test each of the 3 differing outcomes.
int string_compare(char *s, char *t);
returns
<0 if s is lexically before t
0 if s is identical to t
>0 if s is lexically after t
Looking for a simple SQL (PostgreSQL) regular expression or similar solution (maybe soundex) that will allow a flexible search. So that dashes, spaces and such are omitted during the search. As part of the search and only the raw characters are searched in the table.:
Currently using:
SELECT * FROM Productions WHERE part_no ~* '%search_term%'
If user types UTR-1 it fails to bring up UTR1 or UTR 1 stored in the database.
But the matches do not happen when a part_no has a dash and the user omits this character (or vice versa)
EXAMPLE search for part UTR-1 should find all matches below.
UTR1
UTR --1
UTR 1
any suggestions...
I want to change the numbers in my dictionary to int values for use later in my program.
So far I have
import time
import math
x = 400
y = 300
def read_next_object(file):
obj = {}
for line in file:
if not line.strip(): continue
line = line.strip()
key, val = line.split(": ")
if key in obj and key == "Object":
yield obj
obj = {}
obj[key] = val
yield obj
planets = {}
with open( "smallsolar.txt", 'r') as f:
for obj in read_next_object(f):
planets[obj["Object"]] = obj
print(planets)
scale=250/int(max([planets[x]["Orbital Radius"] for x in planets if "Orbital Radius" in planets[x]]))
print(scale)
and the output is
{'Sun': {'Object': 'Sun', 'Satellites': 'Mercury,Venus,Earth,Mars,Jupiter,Saturn,Uranus,Neptune,Ceres,Pluto,Haumea,Makemake,Eris', 'Orbital Radius': '0', 'RootObject': 'Sun', 'Radius': '20890260'}, 'Moon': {'Object': 'Moon', 'Orbital Radius': '18128500', 'Period': '27.321582', 'Radius': '1737000.10'}, 'Earth': {'Object': 'Earth', 'Satellites': 'Moon', 'Orbital Radius': '77098290', 'Period': '365.256363004', 'Radius': '6371000.0'}}
3.2426140709476178e-06
I want to be able to convert the numbers in the dict to ints for further use. Any help in greatly appreciated.
Here is a snap of my database.
Both col1 and col2 are declared as int.
My ComputedColumn currently adds the Columns 1 and 2, as follows...
col1 col2 ComputedColumn
1 2 3
4 1 5
Instead of this, my ComputedColumn should join the columns 1 and 2 (includimg the '-' character in the middle) as follows...
col1 col2 ComputedColumn
1 2 1-2
4 1 4-1
So, what is the correct syntax?
Hi folks,
this is the use case I'm trying to figure this out for.
I have a list of spam subscriptions to a service and they are killing conversion rate and other usability studies.
The emails inserted look like the following:
[email protected][email protected][email protected]
roger[...]_surname[...]@hotmail.com
What would be your suggestions on spotting these entries by using an automated script? It feels a little more complicated than it actually looks.
Help would be very much appreciated!
hi all,
i'm accessing the stylesheet collection like this:
var css = document.styleSheets[0];
it returns eg. http://www.mydomain.com/css/main.css
question: how can i strip the domain name to just get /css/main.css ?
thx
"8,5,,1,4,7,,,,7,,1,9,3,6,,,8,6,3,9,,2,5,4,,,,,3,2,,,7,4,1,1,,4,,6,9,,5,,,,5,,,1,,6,3,,,6,5,,,,7,4,,1,7,6,,,,8,,5,,,7,1,,3,9,"
I'm doing a programming challenge where i need to parse this sequence into my sudoku script.
Need to get the above sequence into 8,5,0,1,4,7,0,0,0,7,0,1,9,3,6,0,0,8.........
I tried re but without success, help is appreciated, thanks.
I am passing in command line arguments to my Lisp program and they are formatted like this when they hit my main function:
("1 1 1" "dot" "2 2 2")
I have a dot function and would like to call it directly from the argument, but first I must strip the " characters.
I tried variations of this function:
(defun remove-quotes (s)
(setf (aref s 0) '""))
to no avail, Lisp complains that "" is not a member of base-char.
Thanks!
I've got a text area on a web site that should be limited in length.
I'm allowing users to enter 255 characters, and am enforcing that limit with a Rails validation:
validates_length_of :body, :maximum => 255
At the same time, I added a javascript char counter like you see on Twitter, to give feedback to the user on how many characters he has already used, and to disable the submit button when over length, and am getting that length in Javascript with a call like this:
element.length
Lastly, to enforce data integrity, in my Postgres database, I have created this field as a varchar(255) as a last line of defense.
Unfortunately, these methods of counting characters do not appear to be directly compatible. Javascript counts the best, in that it counts what users consider as number of characters where everything is a single character. Once the submission hits Rails, however, all of the carriage returns have been converted to \r\n, now taking up 2 characters worth of space, which makes a close call fail Rails validations. Even if I were to handcode a different length validation in Rails, it would still fail when it hits the database I think, though I haven't confirmed this yet.
What's the best way for me to make all this work the way the user would want?
Best Solution: an approach that would enable me to meet user expectations, where each character of any type is only one character. If this means increasing the length of the varchar database field, a user should not be able to sneakily send a hand-crafted post that creates a row with more than 255 letters.
Somewhat Acceptable Solution: a javascript change that enables the user to see the real character count, such that hitting return increments the counter 2 characters at a time, while properly handling all symbols that might have these strange behaviors.