Replace Unless Inside Quotes?
Aug 24, 2014
Basically, I am trying to write a method that will take a string, a target, and a replacement (a replacement function like string.replace). I want it to replace all instances of target with replacement EXCEPT for instances that occur within single or double quotes.
Example input / output:
this "Wont" be " replaced, be"
call: replace(theString, "replaced", "narf") and replace(theString, "be", "rafn")
output:
this "Wont" rafn " replaced, be"
View Replies
ADVERTISEMENT
Mar 17, 2014
how to replace all the command that is found on a string between 2 double quotes? for example I have a text file that contains data like as following
A,"-16,12","-178,245","-15,506"
B,"-16,12","-178,245","-15,506"
C,0, 0,1
I need an output like this:
A,"-16.12","-178.245","-15.506"
B,"-16.12","-178.245","-15.506"
C,0, 0,1
I did this but without regular expression. It seems to me that a regular expression it's more elegant than to parse every line and replace it.
View Replies
View Related
Nov 3, 2014
After opening a file dialog box and choosing a file and the path to that file is placed ina jTextField, How can I surround that text with quotes, if that path contains spaces? This is how I did it in VB.
Function WrapIfRequired(ByVal Filename As String) As String
Dim containsSpaces As Boolean = False
Dim FilePath As String = Filename.Trim
If FilePath.Contains(" ") Then containsSpaces = True
If containsSpaces = True Then
Return """" & FilePath & """"
Else
Return FilePath
End If
View Replies
View Related
Apr 1, 2014
How to maintain quotes in a text file? If no source files .
Новый точечный .jpg
Prompt in what direction to go .... maybe you can use other languages to do it?
Заранее СПасибо!!!
View Replies
View Related
Oct 8, 2014
why when i use the following outputText tag
<h:outputText value="Testone"/>
The generated HTML is
<div>Testone</div>
And when i use the next outputText tag the output is enclosed in quotes
<h:outputText value='<a href="http://some.site.com/login?URL=http://a.b.com/">Some sitelink</a>'/>
"<a href="http://some.site.com/login?URL=http://a.b.com/">Some sitelink</a>"
To temporarily fix something i need to generate an html tag using a param value. Here an example
<h:outputText value="<a href="http://some.domain.nl/login?URL={0}">Hi There</a>">
<f:param value="#{request.scheme}://#{request.serverName}:#{request.serverPort}#{request.contextPath}" />
</h:outputText>
View Replies
View Related
Jan 5, 2015
I'm learning jQuery to integrate into a JSF application but finding some confusion on the correct syntax especially when it comes to combining double and single quotes in the jQuery scripts. So for this particular page I want jQuery to traverse through a list of documents and put icons next to each document to state what type of document each is (ie: PDF, doc, xls). I can get this to work using normal html markup but I get a Syntax Error - Unexpected Token exception in the browser.
I'm confused about whether this means I need to use the right html references for the JSF element I wish to traverse or whether this is a problem with the way I'm using my quotes.
Also I'm not sure how to correctly reference jsf tags inside jQuery scripts. So for an ordinary html page I execute the following jQuery script:
<script type="text/javascript">
$("document").ready(function () {
$("li a[href = ' .pdf']").after("<img src='myImage'/>");
});
</script>
</code>
Then I have a JSF page with the following commandLink:
<p:column>
<p:commandLink class="downLoadLink" value="Download" ajax="false">
<p:fileDownload value="#{projectDocBean.downloadedFile}"
contentDisposition="attachment"/>
</p:commandLink>
</p:column>
For this page I try to execute the following script:
<script type="text/javascript">
$("document").ready(function () {
$("#downLoadLink = ' .pdf']").after("<img src='myImage'/>");
});
</script>
I get the same syntax error no matter what I put into the script of the JSF page. How to correctly integrate jQuery with JSF.
View Replies
View Related
Sep 26, 2014
If I'm using an xml file and the piece of data I want from the file looks like Staff id ="Test";
Is it something like this? Only seen two examples of it but I'm not sure they were reading from a file like myself.
Staff id = """ + Test + """;
View Replies
View Related
Oct 15, 2014
I can't figure out why my code doesn't work. My task is to replace for example ä=>ae, using this method String.charAt(int index). So here is my code:
public class pich {
public static void main(String[] args) {
String text = "Die süße Hündin Leica läuft in die Höhle des fülligen Bären "+
"Iliyan (ein Übergrößenträger), der sie zum Teekränzchen eingeladen hat."+
" An ihrem Öhrchen trägt sie modisch eine Ähre.";
String textOhneUmlaute = "";
[Code] ....
when I launch my code I get the same String and nothing has changed
View Replies
View Related
Mar 2, 2015
How do you replace negative zero value with a zero value when Printing results:
I want to remove the minus sign in -0.0000 and instead have 0.0000.
I am Printing coordinates and I do not want to have negative zero.
the coordinates are defined as double.
System.out.format(java.util.Locale.US," %.4f %.4f %.4f %.4f%n"xCur ,yCur,xNext,yNext);
0.0000 1.0000 -0.0000 0.0000
View Replies
View Related
May 12, 2015
I am trying write a program that accept an input and present the input with every 5th character replaced with X (count spaces also).
For example:
input: "hello my name is mario"
outpu: "hellX my Xame Xi maXio"
I only manage to replace specific letters, e.g every "m" letter.
View Replies
View Related
Sep 11, 2014
I will like replace this code:
// boucle pour les fractions aleatoires
for (i=0; i<2; i++) {
// Creation des fractions aleatoires
Frac first = new Frac(r,5);
Frac second = new Frac(r,5);
[Code] .....
But when I use a switch case I do not have the same result as my four loops.
View Replies
View Related
May 11, 2015
I have a 2D arraylist, named as adjLists, which contains arraylists, containing values like these. Each two values are a "pair" and each third is a "flag" for the pair.
[278, 106, 0, 397, 36, 0, 59, 208, 0, 366, 221, 0]
[366, 221, 0, 397, 36, 0, 132, 390, 0, 278, 106, 0, 295, 0, 0]
I use code above to search for specified value pairs in these lists. vertexnum is the number of "sub arraylists" in adjLists.
for (int l = 0; l < vertexnum; l++) {
if (adjLists.get(l).get(0) == p.x && adjLists.get(l).get(1) == p.y) {
for (int h = 0; h < adjLists.get(l).size(); h += 3) {
for (int g = 0; g < vertexnum; g++) {
if ((vertexSprite[g].getX() + vertexSprite[g].getWidth() / 2) == adjLists.get(l).get(h)
[Code] ....
This code is to search exact values and replace their flag in every occurences. It can not find all the occurences of the values/pair in the lists, it replaces flag value only a few time. Value of score should be incremented with plus 1 after each found occurence, but this code increments it more than the number of matches.
View Replies
View Related
Jan 8, 2014
How can I change the value of
String str = "1234|U||45|||"
into
String str = "1234|U| |45| | |"
View Replies
View Related
Mar 8, 2014
I'm trying to figure out the correct way to replace number into letter. In this case, I need two steps.
First, convert letter to number. Second, restore number to word.
Words list: a = 1, b = 2, f = 6 and k = 11.
I have word: "baafk"
So, for first step, it must be: "211611"
Number "211611" must be converted to "baafk".
But, I failed at second step.
Code I've tried:
public class str_number {
public static void main(String[] args){
String word = "baafk";
String number = word.replace("a", "1").replace("b","2").replace("f","6").replace("k","11");
System.out.println(word);
[Code] .....
Result for converting to number: baafk = 211611 But, result for converting above number to letter: 211611 = bkfk
What do I miss here?
How to distinguish if 11 is for "aa" and for "k"? D
View Replies
View Related
Nov 4, 2014
I have a coauthorship network and I want to replace the authors names with numbers.Part of my datadet:
1992,M_DINE,R_LEIGH,P_HUET,A_LINDE,D_LINDE
1992,C_BURGESS,J_CLINE,M_LUTY
1992,M_DINE,R_LEIGH,P_HUET,A_LINDE,D_LINDE
1992,F_ZWIRNER
1992,O_HERNANDEZ
...
I want the result to be sth like this:
1992 1,2,3,4
1992 5,67
....
and a table of mappings
M_DINE 1
R_LEIGH 2
P_HUET 3
....
I give my dataset in csv (or text) format to my program but it says "(The system cannot find the file specified)" even though the file exists.
what should I do?
here is my code:
Java Code: public class ReadCSV {
HashMap<String, Integer> authorList = new HashMap<>();
File file = new File("d:/Course/thesis/predict/whole.scv");
int authorCounter = 0;
public static void main(String[] args) {
ReadCSV obj = new ReadCSV();
[Code]...
View Replies
View Related
Jul 6, 2014
I was reading a book and came across this while loop.
public class Powers {
public static void main (String [] args){
int e;
int result;
for(int i = 0; i < 10; i++){
[Code] .....
This loop presents the following (I'm sure it's not necessary):
2 to the 0 power is 1
2 to the 1 power is 2
2 to the 2 power is 4
2 to the 3 power is 8
2 to the 4 power is 16
2 to the 5 power is 32
2 to the 6 power is 64
2 to the 7 power is 128
2 to the 8 power is 256
2 to the 9 power is 512
I am just having a difficult time understand and grasping this concept. My main issue is result *=2; this is making it very difficult to understand. How is result being replace if it only equals to 1.
View Replies
View Related
Jul 14, 2014
This is my code:
JDialog dialog = new JDialog();
dialog.setSize(400, 150);
dialog.setTitle("Input dialog");
dialog.add( new JLabel("simtime(min)") );
dialog.add( new JLabel("interval(sec)") );
dialog.setVisible(true);
The problem is that the two lables replace each other.How to position them where we want?
View Replies
View Related
Mar 8, 2014
I'm trying to figure out the correct way to replace number into letter. In this case, I need two steps.
First, convert letter to number. Second, restore number to word.
Words list: a = 1, b = 2, f = 6 and k = 11.
I have word: "baafk"
So, for first step, it must be: "211611"
Number "211611" must be converted to "baafk".
But, I failed at second step.
Code I've tried:
public class str_number {
public static void main(String[] args){
String word = "baafk";
String number = word.replace("a", "1").replace("b","2").replace("f","6").replace("k","11");
System.out.println(word);
[Code] ...
Result for converting to number: baafk = 211611
But, result for converting above number to letter: 211611 = bkfk
How to distinguish if 11 is for "aa" and for "k"? Do you have any solutions or other ways for this case?
View Replies
View Related
Jul 13, 2014
My interest in Java leads me to try and print numbers from 1-100. The output should show all numbers from 1-100 and each number that is divisible by by 13 should be replaced with a string "Fuzzy".
public class Fuzzy {
public static void main (String[]args){
for(int i = 0; i < 100; i++)
if(i % 13==0)
System.out.print(i + "fuzzy");
}
}
View Replies
View Related
Jul 21, 2014
I am trying to custom graphic class..,My task is to replace the specific area color of the image when i select the area & pick the color..,If i choose the hand / body of the T-shirts means the color can change by the user..,
View Replies
View Related
Jan 26, 2015
I am wondering if there is something similar to the "Find and Replace" action, that we use in applications like Eclipse and MS Word, that is actually built into the Java API so we can use it in our code, mainly for method names?
For example, right now I have these couple of lines
rotateLeftCounterClockwise(1);
rotateBottomClockwise(1);
rotateLeftClockwise(1);
//and
rotateRightCounterClockwise(1);
rotateBottomCounterClockwise(1);
rotateRightClockwise(1);
that does one operation for a side of Rubik's cube. However, all other sides of the cube can use these same exact code with the exception of the 2nd word, ie the position, in each method.
So for example, another side would do something, like, lets say
rotateFrontCounterClockwise(1);
rotateBottomClockwise(1);
rotateFrontClockwise(1);
//and
rotateBackCounterClockwise(1);
rotateBottomCounterClockwise(1);
rotateBackClockwise(1);
The reason why I ask this is because this would DRASTICALLY shrink the size my code, rather than have to create separate methods for each operation. Now I know there is a Find and Replace feature for Strings, but I am not sure about method names...
View Replies
View Related
Aug 8, 2014
I'm trying to replace html code with variables from a servlet. Lines with a * won't replace.
String t = screen_configedit.replace( "value="eID"", "value=""+ eid + """);
t = t.replace("value="cID"", "value=""+ cid + """);
t = t.replace("<!-- <br><font color="red">ERROR! Please contact support!</font> -->", "<br><font color="red">ERROR! Please contact support!</font>");
t = t.replace("value="status"", "value=""+ status + """);
[Code] .....
View Replies
View Related
Jan 29, 2015
My question is related to combo boxes. A combo box in general is a text field with a dropdown list. I would want to know if we can replace hthe dropdown List by an other component, for example a JTable component.
View Replies
View Related
Mar 1, 2014
I want to do a simple search and replace regular expression of lines. I am very unfamilar with Java regular expressions, and I'm not sure how to do something as simple as what I want to do. I have lines that look like this...
Java Code : access_log /home/%USER%/access_log mh_sh_highlight_all('java');
I want them changed so %USER% changes to a string, such as "cyrus," so they appear like this ...
Java Code: access_log /home/cyrus/access_log mh_sh_highlight_all('java');
The reason I want to use regular expressions is because I want to use the replaceAll method of the java.lang.String object. If I use replace I have to convert my strings into char arrays, and my code becomes bulky.
View Replies
View Related
Apr 28, 2014
How to replace correct letter with the blanks in the program. Last method in program used to print correct letters.
import java.util.*;
import java.io.*;
public class Hangman {
public static Scanner keyboard;
public static final int MAXSIZE = 15000;
public static final int NUM_GUESS = 8;
public static final int WORD_LENGTH = 20;
[Code] ....
View Replies
View Related
Feb 13, 2015
I am creating a simple code in Java that replaces all tabs the user inputs with '*'. However, I am doing something wrong and I am not sure what. Here is what I have so far in Eclipse..
import java.util.Scanner;
public class ReplacingTabs {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = "";
String s2 = "";
[Code] .....
There is an error with the s2 in the line String s2 = s.replace(' ','*');
I think I need to add String s2 to the loop but I am not sure how..
View Replies
View Related