Hello struggling here guys..
Is it possible to string replace anything between the the first forward slashes with "" but keep the rest?
e.g. var would be
string "/anything-here-this-needs-to-be-replaced123/but-keep-this";
would end up like this
string "/but-keep-this";
Hope that made sence
I have the string
a.b.c.d
I want to count the occurrences of '.' in an idiomatic way, preferably a one-liner.
(Previously I had expressed this constraint as "without a loop", in case you're wondering why everyone's trying to answer without using a loop).
Well it is a basic question but I seem confused enough.
#include<stdio.h>
int main()
{
char a[100];
printf("Enter a string\n");
scanf("%s",a);
}
Basically the above is what I want to achieve.
If I enter a string
James Bond
then I want that to be stored in array a.
But the problem is because of presence of a blank space in between only James word is stored.
So how can I solve this one.
UPDATE
After the replies given below I understand fgets() would be a better choice. I want to know internal working of fgets as why is it able to store the string with space where as scanf is not able to do the same.
Hiii....
I am developing small spring application. I have to store the details of the student information in the database. I have develop one simpleformcontroller.
I have used netbeans + hibernate mapping + spring. when I submit the form, jsp page is redirect on the same page and control does not go to Formcontroller..
I tried the below query but it didnt executed giving error as :
1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server
version for the right syntax to use
near ')' at line 1
INSERT INTO `jos_menu` SET params = 'orderby= show_noauth= show_title= link_titles= show_intro= show_section= link_section= show_category= link_category= show_author= show_create_date= show_modify_date= show_item_navigation= show_readmore= show_vote= show_icons= show_pdf_icon= show_print_icon= show_email_icon= show_hits= feed_summary= page_title= show_page_title=1 pageclass_sfx= menu_image=-1 secure=0 ', checked_out_time = '0000-00-00 00:00:00', ordering = '13', componentid = '20', published = '1', id = '152', menutype = 'accmenu', name = 'IPL', alias = 'ipl', link = 'index.php?option=com_content&view=archive', type = 'component')
then i used mysql_real_escape_string() on the query containing variable which gives me the query as :
INSERT INTO `jos_menu` SET params = \'orderby=\nshow_noauth=\nshow_title=\nlink_titles=\nshow_intro=\nshow_section=\nlink_section=\nshow_category=\nlink_category=\nshow_author=\nshow_create_date=\nshow_modify_date=\nshow_item_navigation=\nshow_readmore=\nshow_vote=\nshow_icons=\nshow_pdf_icon=\nshow_print_icon=\nshow_email_icon=\nshow_hits=\nfeed_summary=\npage_title=\nshow_page_title=1\npageclass_sfx=\nmenu_image=-1\nsecure=0\n\n\', checked_out_time = \'0000-00-00 00:00:00\', ordering = \'13\', componentid = \'20\', published = \'1\', id = \'152\', menutype = \'accmenu\', name = \'IPL\', alias = \'ipl\', link = \'index.php?option=com_content&view=archive\', type = \'component\')
And on executing the above query I get an error as :
1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server
version for the right syntax to use
near
'\'orderby=\nshow_noauth=\nshow_title=\nlink_titles=\nshow_intro=\nshow_section=\' at line 1
Can Someone guide me to track the problem in it?
Thanks In Advance....
Hi everyone,
I'm looking for a simple Flex or JavaScript based image editing component which can be embedded in a web application. It shouldn't be a web service but rather a component that I can download and customize (i18n etc.).
I only need some basic features: most important is cropping, optional features would be rotating and adjusting brightness/contrast.
Basically something like splashup.com, but as an open source application rather than a web-service.
Thanks a lot in advance for any hints!
-- Andreas
I have a string like
def data = "session=234567893egshdjchasd&userId=12345673456&timeOut=1800000"
I want to convert it to a map
["session", 234567893egshdjchasd]
["userId", 12345673456]
["timeout", 1800000]
This is the current way I am doing it,
def map = [:]
data.splitEachLine("&"){
it.each{ x ->
def object = x.split("=")
map.put(object[0], object[1])
}
}
It works, but is there a more efficient way?
The problem is: given an integer val1 find the position of the highest bit set (Most Significant Bit) then, given a second integer val2 find a contiguous region of unset bits, with the minimum number of zero bits given by width to the left of the position (ie, in the higher bits).
Here is the C code for my solution:
typedef unsigned int t;
unsigned const t_bits = sizeof(t) * CHAR_BIT;
_Bool test_fit_within_left_of_msb( unsigned width,
t val1,
t val2,
unsigned* offset_result)
{
unsigned offbit = 0;
unsigned msb = 0;
t mask;
t b;
while(val1 >>= 1)
++msb;
while(offbit + width < t_bits - msb)
{
mask = (((t)1 << width) - 1) << (t_bits - width - offbit);
b = val2 & mask;
if (!b)
{
*offset_result = offbit;
return true;
}
if (offbit++) /* this conditional bothers me! */
b <<= offbit - 1;
while(b <<= 1)
offbit++;
}
return false;
}
Aside from faster ways of finding the MSB of the first integer, the commented test for a zero offbit seems a bit extraneous, but necessary to skip the highest bit of type t if it is set.
I have also implemented similar algorithms but working to the right of the MSB of the first number, so they don't require this seemingly extra condition.
How can I get rid of this extra condition, or even, are there far more optimal solutions?
Edit: Some background not strictly required. The offset result is a count of bits from the high bit, not from the low bit as maybe expected. This will be part of a wider algorithm which scans a 2D array for a 2D area of zero bits.
Here, for testing, the algorithm has been simplified. val1 represents the first integer which does not have all bits set found in a row of the 2D array. From this the 2D version would scan down which is what val2 represents.
Here's some output showing success and failure:
t_bits:32
t_high: 10000000000000000000000000000000 ( 2147483648 )
---------
-----------------------------------
*** fit within left of msb test ***
-----------------------------------
val1: 00000000000000000000000010000000 ( 128 )
val2: 01000001000100000000100100001001 ( 1091569929 )
msb: 7
offbit:0 + width: 8 = 8
mask: 11111111000000000000000000000000 ( 4278190080 )
b: 01000001000000000000000000000000 ( 1090519040 )
offbit:8 + width: 8 = 16
mask: 00000000111111110000000000000000 ( 16711680 )
b: 00000000000100000000000000000000 ( 1048576 )
offbit:12 + width: 8 = 20
mask: 00000000000011111111000000000000 ( 1044480 )
b: 00000000000000000000000000000000 ( 0 )
offbit:12
iters:10
***** found room for width:8 at offset: 12 *****
-----------------------------------
*** fit within left of msb test ***
-----------------------------------
val1: 00000000000000000000000001000000 ( 64 )
val2: 00010000000000001000010001000001 ( 268469313 )
msb: 6
offbit:0 + width: 13 = 13
mask: 11111111111110000000000000000000 ( 4294443008 )
b: 00010000000000000000000000000000 ( 268435456 )
offbit:4 + width: 13 = 17
mask: 00001111111111111000000000000000 ( 268402688 )
b: 00000000000000001000000000000000 ( 32768 )
***** mask: 00001111111111111000000000000000 ( 268402688 )
offbit:17
iters:15
***** no room found for width:13 *****
(iters is the count of iterations of the inner while loop)
Is this the right method to reverse a string? I'm planning to use it to reverse a string like: Products » X1 » X3 to X3 « X1 « Products
I want it to be a global function which can be used elsewhere.
public static string ReverseString(string input, string separator, string outSeparator)
{
string result = String.Empty;
string[] temp = Regex.Split(input, separator, RegexOptions.IgnoreCase);
Array.Reverse(temp);
for (int i = 0; i < temp.Length; i++)
{
result += temp[i] + " " + outSeparator + " ";
}
return result;
}
I have a large image, size around 30000 (w) x 6000 (h) pixels. You may consider it's like a big map. I assume I need to crop it up into smaller tiles. Questions:
what are the right ViewControllers to use?
(link) what is the tile strategy? (I put this in another question, as it's not iPhone specific)
Requirements:
whole image (though cropped) can be scrolled up/down/left/right by swipes
zoom in (up to pixel-to-pixel) out (down to screen-fit-by-height) by the 2-finger operation
memory efficiency by lazy loading tiles
Bonus requirements:
automatic scroll, say from left to right slowly and smoothly
Thanks!
How can I use PHP to strip out all characters that are NOT alpha, numeric, space, or puncutation?
I've tried the following, but it strip punctuation.
preg_replace("/[^a-zA-Z0-9\s]/", "", $str);
I have a query that is using multiple joins. The goal is to say "Out of table A, give me all the customer numbers in which you can match table A's EmailAddress with either email_to or email_from of table B. Ignore nulls, internal emails, etc.".
It seems like it would be better to use an or condition in the join than multiple joins since it is the same table. When I try to use AND/OR it does not give the behaviour I expect... AND finishes in a reasonable time, but yields no results (I know that there are matches, so it must be some flaw in my logic) and OR never finishes (I have to kill it).
Here is example code to illustrate the question:
--my original query
SELECT DISTINCT a.CustomerNo
FROM A a WITH (NOLOCK)
LEFT JOIN B e WITH (NOLOCK) ON a.EmailAddress = e.email_from
RIGHT JOIN B f WITH (NOLOCK) ON a.EmailAddress = f.email_to
WHERE a.EmailAddress NOT LIKE '%@mydomain.___'
AND a.EmailAddress IS NOT NULL
AND (e.email_from IS NOT NULL OR f.email_to IS NOT NULL)
Here is what I tried, (I am attempting logical equivalence):
SELECT DISTINCT a.CustomerNo
FROM A a WITH (NOLOCK)
LEFT JOIN B e WITH (NOLOCK)
ON a.EmailAddress = e.email_from OR a.EmailAddress = e.email_to
WHERE a.EmailAddress NOT LIKE '%@mydomain.___'
AND a.EmailAddress IS NOT NULL
AND (e.email_from IS NOT NULL OR e.email_to IS NOT NULL)
So my question is two-fold:
Why does having AND in the above query work in a few seconds and OR
goes for minutes and never completes?
What am I missing to make a logically equivalent statement that
has only one join?
Hello everyone,
Basically, we have an ASP website right now that I'm converting to PHP. We're still using the MSSQL server for the DB -- it's not moving.
In the ASP, now, there's an include file with a giant sql query that's being executed. This include sits on a lot of pages and this is a simple version of what happens. Pages A, B and C all use this include file to return a listing.
In ASP, Page A passes through variable A to the include file - page B passes through variable B -- page C passes through variable C, and so on.
The include file builds the SQL query like this:
sql = "SELECT * from table_one LEFT OUTER JOIN table_two ON table_one.id = table_two.id"
then adds (remember, ASP), based on the variable passed through from the parent page,
Select Case sType
Case "A"
sql = sql & "WHERE LOWER(column_a) <> 'no' AND LTRIM(ISNULL(column_b),'') <> '' ORDER BY column_a
Case "B"
sql = sql & "WHERE LOWER(column_c) <> 'no' ORDER BY lastname, firstname
Case "C"
sql = sql & "WHERE LOWER(column_f) <> 'no' OR LOWER(column_g) <> 'no' ORDER BY column_g
As you notice, every string that's added on as the second part of the sql query is different than the previous; not just one variable can be substituted out, which is what has me stumped.
How do I translate this case / switch into the stored procedure, based on the varchar input that I pass to the stored procedure via PHP?
This stored procedure will actually handle a query listing for about 20 pages, so it's a hefty one and this is my first major complicated one. I'm getting there, though! I'm also just more used to MySQL, too. Not that they're that different. :P
Thank you very much for your help in advance.
Stephanie
Hello,
I want to add a resize function to my app which works like the integrated copy feature on the iPhone. When the user opens the view he should see the image with the four blue dots which enable him to resize it. Is there an available example for this? Or has anyone the keywords for this functionality, which i can use for my further Search?
Thanks for all tips and hints
Hi all!
I Use this code:
NSString* strName = [NSString stringWithFormat:@"img_00%d.jpg", pp];
and works fine, but if pp took the value of 10 for example I wish have img_010.jpg as result, and not img_0010.jpg...
how can I format the string??
thanks
I'm dealing with a problem which needs to work with a lot of data. Currently its' values are represented as unsigned int. I know that real values do not exceed some limit, say 1000. That means that I can use unsigned short to store it. One profit is that it'll use less space. Do I have to pay for it by loosing in performance?
Another assumption. I decided to store data as short but all calling functions use int, so I need to convert between these datatypes when storing/extracting values. Wiil the performance lost be dramatic?
Third assumption. Due to great wish to econom memory I decided to use not short but just 10 bits packed into array of unsigned int. What will happen in this case comparing with previous ones?
Hello,
I have a database in PostgreSQL and I'm developing an application in PHP using this database.
The problem is that when I execute the following query I get a nice result in phpPgAdmin but in my PHP application I get an error.
The query:
SELECT t.t_name, t.t_firstname
FROM teachers AS t
WHERE t.id_teacher IN (SELECT id_teacher FROM teacher_course AS tcourse
JOIN course_timetable AS coursetime
ON tcourse.course = coursetime.course
AND to_char(to_timestamp('2010-4-12', 'YYYY-MM-DD'),'FMD') = (coursetime.day +1))
AND t.id_teacher NOT IN (SELECT id_teacher FROM teachers_fill WHERE date = '2010-4-12')
ORDER BY t.t_name ASC
And this is the error in PHP
operator does not exist: text = integer (to_timestamp('', 'YYYY-MM-DD'),'FMD') =
(courset... ^ HINT: No operator matches the given name and argument type(s).
You might need to add explicit type casts.
The purpose to solve this error is to use the ORIGINAL query in php with :
$date = "2010"."-".$selected_month."-".$selected_day;
SELECT t.t_name, t.t_firstname
FROM teachers AS t
WHERE t.id_teacher IN (SELECT id_teacher FROM teacher_course AS tcourse
JOIN course_timetable AS coursetime
ON tcourse.course = coursetime.course
AND to_char(to_timestamp('$date', 'YYYY-MM-DD'),'FMD') = (coursetime.day +1))
AND t.id_teacher NOT IN (SELECT id_teacher FROM teachers_fill WHERE date = '$date')
ORDER BY t.t_name ASC
I like to replace a certain set of characters of a string with a corresponding replacement character in an efficent way.
For example:
String sourceCharacters = "šdccŠÐCCžŽ";
String targetCharacters = "sdccSDCCzZ";
String result = replaceChars("Gracišce", sourceCharacters , targetCharacters );
Assert.equals(result,"Gracisce") == true;
Is there are more efficient way than to use the replaceAll method of the String class?
My first idea was:
final String s = "Gracišce";
String sourceCharacters = "šdccŠÐCCžŽ";
String targetCharacters = "sdccSDCCzZ";
// preparation
final char[] sourceString = s.toCharArray();
final char result[] = new char[sourceString.length];
final char[] targetCharactersArray = targetCharacters.toCharArray();
// main work
for(int i=0,l=sourceString.length;i<l;++i)
{
final int pos = sourceCharacters.indexOf(sourceString[i]);
result[i] = pos!=-1 ? targetCharactersArray[pos] : sourceString[i];
}
// result
String resultString = new String(result);
Any ideas?
Btw, the UTF-8 characters are causing the trouble, with US_ASCII it works fine.
I resized an image using Java2D Graphics class. But it doesn't look right.
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();
Is it possible to scale an image without introducing artifacts?
I would like to trim all special characters from a string in SQL. I've seen a bunch of people who use substring methods to remove a certain amount of characters, but in this case the length on each side of the string is unknown.
Anyone know how to do this?
Thanks,
Matt
(this is related to another question about implementation on iPhone)
I have a large image, size around 30000 (w) x 6000 (h) pixels. You may consider it's like a big map. I assume I need to crop it up into smaller tiles. Questions:
what is the tile strategy?
Requirements:
whole image (though cropped) can be scrolled up/down/left/right by swipes
zoom in (up to pixel-to-pixel) out (down to screen-fit-by-height) by the 2-finger operation
memory efficiency by lazy loading tiles
Thanks!
"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.