2014年11月

How to find all special characters and print them in a given string?

I need to find all special characters and even the spaces in a sting and print it as a out put..



I have tried the following.



public class SpecialChar {

public static void main(String[] args) {

String s = "adad , dsd r dsdsd,,,,..////";

for (int i = 0; i < s.length(); i++)
{
System.out.println(s.charAt(i));
}

System.out.println("i");


String REGEX = "[^&%$#@!~ ,]*";
Pattern pattern = Pattern.compile(REGEX);

Matcher matcher = pattern.matcher(i);
if (matcher.matches()) {
System.out.println("matched");
}
}
}


Answers

A little regex will work for you :)



public static void main(String[] args) {
String s = "adad , dsd r dsdsd,,,,..////";
System.out.println(s.replaceAll("[a-zA-Z]+", "")); // remove everything apart from "a-z and A-Z"

}


O/P:



 ,    ,,,,..////


Answers

I just want to point out to your problem, you're using the following regex:



[^&%$#@!~ ,]*


which means "any literal expect one of "&%$#@!~ ,".



Note that your set begins with ^, this means that it negates the set and matches every literal that's not in that set.



You have two options: Escape the ^, or move it to the last position.



Answers

I don't know if this is what you need but here it is:



       String s = "adad , dsd  r dsdsd,,,,..////";

String REGEX = "[,./]";
Pattern pattern = Pattern.compile(REGEX);
Matcher matcher = pattern.matcher(s);

for (int i = 0; i < s.length(); i++) {
if (matcher.find()) {
System.out.println(matcher.group(0));
}
}


Answers

If you do not want to use regex, you could try the following:



public static void main(String[] args) {

String s = "adad , dsd r dsdsd,,,,..////";
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (!Character.isLetterOrDigit(c)) {
System.out.print(c);
}
}

}


Here you use the existing API in Character class which will be used to check if a character is a letter or a digit, if not print it.



Answers

public class SpecialChar {

public static void main(String[] args) {
String s = "adad , dsd r dsdsd,,,,..////";

for (int i = 0; i < s.length(); i++) {
if (!(((int) s.charAt(i) >= 65 && (int) s.charAt(i) <= 90) || ((int) s.charAt(i) >= 97 && (int) s.charAt(i) <= 122)))
System.out.println(s.charAt(i));
}
}
}




Media Query to Match Bootstrap -xs, -sm, etc. modifiers? [duplicate]

This question already has an answer here:




Twitter Bootstrap 3: how to use media queries?

11 answers

Answers

Based on your Bootstrap helper class, logically you can use the below media query.



.hidden-xs targets elements within 768px and hides it, .visible-md will target above 768px and within 992px.



Visible-sm



@media (min-width: 768px) and (max-width: 992px) {
.center-block {
display: block;
margin-left: auto;
margin-right: auto;
}
}


Hidden-xs



@media (max-width: 768px) {
.center-block {
display: block;
margin-left: auto;
margin-right: auto;
}
}




using a variable defined in one php file in another php file

In my adminpage.php I have two hyperlinks which displayed asoption1 ,option2. What I want is when Admin selects option1 it directs to a page named as adminOption1.php and in this page I want to set in a variable, say named as 'adminType' ($adminType=option1) so that I can use the variable adminType in a different php file say, adminDisplay.php. So that in adminDisplay.php based on whether adminType is set to option1 or option2 I can view different outputs.This admin's options are not stored in the database, it solely depends on the link which he clicks.



Can I set this as a session variable? I have my sessions as,



$sql=mysql_query("SELECT * FROM member WHERE `userName`='$n' AND password`='$p'");

if(mysql_num_rows($sql)==1) {
$_SESSION['user']=mysql_fetch_array($sql);


and my member table has only id, name and userName as fields.
How can I do this.





Why is this SVG image blurry when scaled down?

I am making a responsive web page using the Bootstrap 3 framework. I have an image that I want to use as a logo on the page.



I started off saving the full size (788 x 1098) image as a PNG. My custom CSS makes sure the image has a max-width of 280px and of course Bootstrap's CSS will scale down the image appropriately for the device. When I viewed my responsive web page on my desktop PC it looked ok even though it had been scaled down to 197 x 280. However when I viewed it on my mobile the image looked blurry and wasn't good at all.



So then I heard about SVG images and thought I'd give it a go. I downloaded Inkscape for Mac, opened the full size PNG in Inkscape and re-saved as a SVG image. Unexpectedly the SVG image looks good when I view my web page on my mobile phone but looks blurry and bad when viewed on my desktop PC.



Why is this? I thought the whole point of SVG images was that they can be scaled without loss or blurriness?



I've made a CodePen to help demonstrate: http://codepen.io/theclarkofben/pen/WvdKgM



<p>SVG 20%</p>
<img src="http://www.clarkben.com/img/cv.svg" alt="a" style="height: 20%; width: 20%;"/>
<p>SVG 100%</p>
<img src="http://www.clarkben.com/img/cv.svg" alt="a" />


Answers

Your "SVG" is just SVG containing single raster (PNG) image, so nothing really scalable; see <image … in view-source:http://www.clarkben.com/img/cv.svg.



You can control rendering of such raster a bit with CSS (either using image-rendering or forcing GPU to handle that via some transform, but result woudn't be perfect either. Anyway, even it this was vector image, rendering A4 into cca 300 screen pixels wide box would not be "readable" as well, in my oppinion.



Answers

It looks like the image is still just a PNG image; it's just masquerading as an SVG because you gave it that extension without actually converting it to SVG. You can't really convert a PNG to an SVG by just opening it in inkscape and saving the image as SVG -- you need to either recreate the image from scratch as an SVG or look up how to turn a raster image into an svg image.



Answers

Try using polyfill.js it solves a few of these problems.



On the other hand, that fine line inside your logo is so thin, that when transfered to a square-pixel-base it might not look that perfectly. The whole point with svg is, that it can display the image on every display in the best possible way. But we are still down to display everything on a square-pixel base. Your phone might have a high pixel density so it can display it more smoothly than the desktop.





Question

how much awarded to the family of a man killed by a high school bus in south carolina? the bus pulled out to make a left turn and did not see him.



Answer

That depends on a number of factors. I would need some more information. There is certain evidence that can be presented that could make a big difference.



You can call me and I can fill you in. I'm an attorney with a law firm in Horry County. We handle cases throughout the state. I don't charge for these calls so please feel free to contact me.



Robert J. Johnston


843-946-0099





↑このページのトップヘ