/^[^\s]+\s([^\s]+)\s/
In PHP,I can use regex to get the substr by $1,
how should I do it in C?
It's better if can do it without regex,though.
UPDATE
Put simply, how do I get werwerur out of swerwer werwerur y (the second)?
I'm looking for the easiest way to sort an array that consists of numbers and text, and a combination of these.
E.g.
'123asd'
'19asd'
'12345asd'
'asd123'
'asd12'
turns into
'19asd'
'123asd'
'12345asd'
'asd12'
'asd123'
This is going to be used in combination with the solution to another question I've asked here.
The sorting function in itself works, what I need is a function that can say that that '19asd' is smaller than '123asd'.
I'm writing this in JavaScript.
Hi all,
I have a set of data that contains garbled text fields because of encoding errors during many import/exports from one database to another. Most of the errors were caused by converting UTF-8 to ISO-8859-1. Strangely enough, the errors are not consistent: the word 'München' appears as 'München' in some place and as 'MÜnchen'.
Is there a trick in SQL server to correct this kind of crap? The first thing that I can think of is to exploit the COLLATE clause, so that ü is interpreted as ü, but I don't exactly know how. If it isn't possible to make it in the DB level, do you know any tool that helps for a bulk correction? (no manual find/replace tool, but a tool that guesses the garbled text somehow and correct them)
Hi
I am trying to dump the floating point values from my program to a bin file. Since I can't use any stdlib function, I am thinking of writting it char by char to a big char array which I am dumping in my test application to a file.
It's like
float a=3132.000001;
I will be dumping this to a char array in 4 bytes.
Code example would be:-
if((a < 1.0) && (a > 1.0) || (a > -1.0 && a < 0.0))
a = a*1000000 // 6 bit fraction part.
Can you please help me writting this in a better way.
Well since it seems relatively difficult to send the object of a WebControl over JSON using jquery.ajax() I've decided to send the name of the control as a string because I know how to do that. Then I promptly realized that, from a web service, I don't actually know how to search for a control by ID name. Since its a service I can't seem to get Control.FindControl() to work so does anyone have ideas or suggestions? All I'm trying to do is call a databind() on my radcombobox.
Thanks in advance!
For any of you that knows anything about asp.net/rad controls - I'm basically updating a database and want the radcombobox to be in sync with that database again after adding something, before I autoselect what was just added. Other than databind do i have to call anything to refresh that list?
Thanks again!
I have SEF urls like /sitename/section/12-news-title and number 12 is id of the news. I need to get that number 12 in my php code, is there any out of the box method in PHP for this?
I have code like that:
TEXT_TO_FILTER='I would like to replace this $var to proper value'
var=variable
All I want to get is:
TEXT_AFTER_FILTERED="I'd like to replace this variable to proper value"
So I did:
TEXT_AFTER_FILTERED=`eval echo $TEXT_TO_FILTER`
TEXT_AFTER_FILTERED=`eval echo $(eval echo $TEXT_TO_FILTER)`
Or even more weirder things, but without any effects.
I remember that someday I had similar problem and I did something like that:
cat << EOF > tmp.sh
echo $TEXT_TO_FILTER
EOF
chmod +x tmp.sh
TEXT_AFTER_FILTERED=`. tmp.sh`
But this solution seems to be to much complex.
Have any of You heard about easier solution?
Working in ASP.NET (VB), I am trying to develop a simple search results page for my website.
The process is as follows:
(1) The site's user enters a search phrase;
(2) The search results page searched the site's database, and returns the page title as a link, and a short snippet from each search "hit", with the search phrase highlighted.
I already have the search part done, and also the "highlighted" part done (using Regex). However, I want to be able to return a short snippet of text, which include the search phrase (a few words before the search phrase, a few after). Something like:
Page Title [as a link]
... yada yada yada search phrase yada yada yada...
Could someone take a look at this code and find out what's wrong with it?
#!/bin/sh
while :
do
echo " Select one of the following options:"
echo " d or D) Display today's date and time"
echo " l or L) List the contents of the present working directory"
echo " w or W) See who is logged in"
echo " p or P) Print the present working directory"
echo " a or A) List the contents of a specified directory"
echo " b or B) Create a backup copy of an ordinary file"
echo " q or Q) Quit this program"
echo " Enter your option and hit <Enter>: \c"
read option
case "$option" in
d|D) date
;;
l|L) ls $PWD
;;
w|w) who
;;
p|P) pwd
;;
a|A) echo "Please specify the directory and hit <Enter>: \c"
read directory
if [ "$directory = "q" -o "Q" ]
then
exit 0
fi
while [ ! -d "$directory" ]
do
echo "Usage: "$directory" must be a directory."
echo "Re-enter the directory and hit <Enter>: \c"
read directory
if [ "$directory" = "q" -o "Q" ]
then
exit 0
fi
done
printf ls "$directory"
;;
b|B) echo "Please specify the ordinary file for backup and hit <Enter>: \c"
read file
if [ "$file" = "q" -o "Q" ]
then
exit 0
fi
while [ ! -f "$file" ]
do
echo "Usage: \"$file\" must be an ordinary file."
echo "Re-enter the ordinary file for backup and hit <Enter>: \c"
read file
if [ "$file" = "q" -o "Q" ]
then
exit 0
fi
done
cp "$file" "$file.bkup"
;;
q|Q) exit 0
;;
esac
echo
done
exit 0
There are some syntax errors that I can't figure out. However I should note that on this unix system echo -e doesn't work (don't ask me why I don't know and I don't have any sort of permissions to change it and even if I wouldn't be allowed to)
Bash Shell Scripting Error: "./myDemo ./myDemo: line 62: syntax error near unexpected token done' ./myDemo: line 62: " [Edited]
EDIT: I fixed the while statement error, however now when I run the
script some things still aren't
working correctly.
It seems that in the b|B) switch statement
cp $file $file.bkup doesn't
actually copy the file to file.bkup ?
In the a|A) switch statement
ls "$directory" doesn't print the directory listing for the user to see
?
#!/bin/bash
while $TRUE
do
echo " Select one of the following options:"
echo " d or D) Display today's date and time"
echo " l or L) List the contents of the present working directory"
echo " w or W) See who is logged in"
echo " p or P) Print the present working directory"
echo " a or A) List the contents of a specified directory"
echo " b or B) Create a backup copy of an ordinary file"
echo " q or Q) Quit this program"
echo " Enter your option and hit <Enter>: \c"
read option
case "$option" in
d|D) date
;;
l|L) ls pwd
;;
w|w) who
;;
p|P) pwd
;;
a|A) echo "Please specify the directory and hit <Enter>: \c"
read directory
if [ ! -d "$directory" ]
then
while [ ! -d "$directory" ]
do
echo "Usage: "$directory" must be a directory."
echo "Specify the directory and hit <Enter>: \c"
read directory
if [ "$directory" = "q" -o "Q" ]
then
exit 0
elif [ -d "$directory" ]
then
ls "$directory"
else
continue
fi
done
fi
;;
b|B) echo "Specify the ordinary file for backup and hit <Enter>: \c"
read file
if [ ! -f "$file" ]
then
while [ ! -f "$file" ]
do
echo "Usage: "$file" must be an ordinary file."
echo "Specify the ordinary file for backup and hit <Enter>: \c"
read file
if [ "$file" = "q" -o "Q" ]
then
exit 0
elif [ -f "$file" ]
then
cp $file $file.bkup
fi
done
fi
;;
q|Q) exit 0
;;
esac
echo
done
exit 0
Another thing... is there an editor that I can use to auto-parse code? I.e something similar to NetBeans?
This script should detect the last portion in the full path, and if it is stackoverflow output ok
$current_url = $_SERVER['REQUEST_URI'];
$current_url_arr = explode('/',$current_url);
$count = count($current_url_arr);
if($current_url_arr[$count-2] == 'stackoverflow'){
echo 'ok';
}
else {
echo 'not ok';
}
Example 1: www.myserver.ext/something/else/stackoverflow/
Output: ok
Example 2: www.myserver.ext/something/else/stackoverflow
Output: not ok
Example 3: www.myserver.ext/something/else/stackoverflow/foo
Output: not ok
I hope that you understand the idea. This script works fine, but I'm wondering if there is any better, elegant way to read last portion of URL?
Hello,
I have a complicated form where I first have to take some _GET parameters and obviously I have to do a mysql_real_escape_string() on them since I look stuff up in the database with them.
Them problem for me is after the initial db lookup. When the user submits a form, I send them along as a _POST request and obviously have to do this mysql_real_escape_string call again just in case someone tries to hack my site with a faked form submission.
Then the problem I have is the arguments are escaped twice and my queries begin to look strange like this:
select field1 , field2 , from my_table where some_id = \'.$lookup_id.\' ...
So the system seems to be adding \' and it is messing me up :)
Also, in my other forms I have not seen such behavior. Any ideas on what may be causing this?
One weird thing is that I tried to send unescaped parameters to the post, and the same problem happens. That is a clue, but not a sufficient one for me. :(
Thanks,
Alex
The challenge: The shortest code, by character count, that detects and removes duplicate characters in a String. Removal includes ALL instances of the duplicated character (so if you find 3 n's, all three have to go), and original character order needs to be preserved.
Example Input 1:
nbHHkRvrXbvkn
Example Output 1:
RrX
Example Input 2:
nbHHkRbvnrXbvkn
Example Output 2:
RrX
(the second example removes letters that occur three times; some solutions have failed to account for this)
(This is based on my other question where I needed the fastest way to do this in C#, but I think it makes good Code Golf across languages.)
function FM_log(level, text) {
// caso não seja log total escolhe o que loga
var log = false;
switch (level) {
case "addtoprio()":log = true;
case "alternaTropas()":log = false;
case "sendtroops()":log = false;
defalt: log = false;
}
if ((logTotal == false) && (log == true))
GM_log(horaAtual() + " - "+level+", "+text);
else if (logTotal == true)
GM_log(horaAtual() + " - "+level+", "+text);
}
how to do that switch is a way it works?
I have got a file with following format.
1234, 'US', 'IN',......
324, 'US', 'IN',......
...
...
53434, 'UK', 'XX', ....
...
...
253, 'IN', 'UP',....
253, 'IN', 'MH',....
Here I want to extract only those lines having 'IN' as 2nd keyword. i.e.
253, 'IN', 'UP',....
253, 'IN', 'MH',....
Can any one please tell me a command to grep it.
Hello,
I have a database on a SQL Server 2000 server. This database has a table called "Person" that has a field call "FullName" that is a VARCHAR(100).
I am trying to write a query that will allow me to get all records that have a name. Records that do not have a name have a FullName value of either null or an empty string. How do I get all of the Person records have a FullName? In other words, I want to ignore the records that do not have a FullName. Currently I am trying the following:
SELECT
*
FROM
Person p
WHERE
p.FullName IS NOT NULL AND
LEN(p.FullName) > 0
Thank you
Hi all,
This is probably seriously easy to solve for most of you but I cannot solve this simply putting str() around it can I?
I would like to convert this list: ['A','B','C'] into 'A B C'.
Thanks in advance!!
Hello, I'm writing an IRCd. For this topic it doesn't really matter if you know much about IRC. Its a simple code style problem.
Quick overview of the problem:
No message may be longer than 512 characters
If the message is more, it must be broken into pieces
The NAMES reply sends all the nicknames of users on a channel, and quickly grows beyond 512 characters.
I currently concocted this marvelous piece of code, it works perfectly. However, its just not "ruby-like". This piece of code is more what you expect in some piece of C code.
# 11 is the number of all fixed characters combined in the reply
pre_length = 11 + servername.length + mynick.length + channel.name.length
list = [""]
i = 0
channel.nicks.each do |nick, client|
list[i+=1] = "" if list[i].length + nick.length + pre_length > 500
list[i] << "#{channel.mode_char(client)}#{client.nick} "
end
list.each { |l| send_numeric(RPL_NAMREPLY, channel.name, l.strip) }
send_numeric(RPL_ENDOFNAMES, channel.name)
So my question is, any ideas to do this more nicely?
PS. code has been slightly modified to make it easier to understand out-of-context
I've seen questions to prefix zeros here in SO. But not the other way !!
Can you guys suggest me how to remove the leading zeros in alphanumeric text. Are there any built-in APIs or do I need to write a method to trim the leading zero's?
Example:
01234 converts to 1234
0001234a converts to 1234a
001234-a converts to 1234-a
101234 remains as 101234
2509398 remains as 2509398
123z remains as 123z
000002829839 converts to 2829839
Hi,
do you know any good algorithms that match two strings and then return a percentage in how many percent those two strings match?
And are there some, that work with databases too?
Right now I am seeing if a sentence contains a specific word by splitting the sentence into an array and then doing an include to see if it contains the word. Something like:
"This is my awesome sentence.".split(" ").include?('awesome')
But I'm wondering what the fastest way to do this with a phrase is. Like if I wanted to see if the sentence "This is my awesome sentence." contains the phrase "my awesome sentence". I am scraping sentences and comparing a very large number of phrases, so speed is somewhat important.
I am trying to reuse some of my tiles in a controller which is returning a json response to the client. I would like to return a json response similar to the following format:
{
'success': <true or false>,
'response': <the contents of an apache tile>
}
In my controller I would like to perform logic similar to this pseudocode:
boolean valid = validator.validate(modelObj)
String response = ""
if(valid){
response = successView.render() // im looking for a way to actually accomplish
// this, where the successView is the apache tiles view.
// I would also need to pass a model map to the view somehow.
}else{
response = errorView.render()
}
writeJsonResponse(httpResponse, /* a Map whose json representation looks like the one I described above. */)
What is the best way to achieve sscanf-like functionality in perl?
I am looking now looking at the sscanf module,
Which is better,
Option-1: Going sscanf way?
Option-2: Regex way? [I am a beginner when it comes to Regex]
Hello everybody!
I have one small problem. I have list of types(int,string,..)
ArrayList<Class> typeList;
and I have some input values;
ArrayList<Object> values;
How to cast some value to some type if I know which type from the typeList is the values;
typeList.get(i).cast(values.get(i)); <- this is not working???
Actualy I generate dynamic form in runtime.
With Java reflection I get parameterTypes from methods from some class, I generate form with input fields and then i want to cast the text from the input fields to specific types from the paramterTypes that I got with Java reflection from some class.
What is a better way to program the following SQL:
str_to_date(
concat(convert(D.DAY, CHAR(2)),
'-',
convert(M.MONTH, CHAR(2)),
'-',
convert(M.YEAR, CHAR(4))),
'%e-%m-%Y' ) as AMOUNT_DATE
I want to convert the columns D.DAY, M.MONTH, and M.YEAR to a date field using MySQL. The above works, but seems much more complicated than it needs to be. (If there's an ANSI SQL way to do it, that would be even better.)
Thank you!