Hey all,
I want to use \ in a string, like
string str="abc\xyz";
But this is giving me error.
I have also tried
string str="abc\\xyz";
But still it isnt working.
Can anyone help me out?
I have an xml file...
<?xml version="1.0" encoding="UTF-8"?>
<items defaultNode="1">
<default contentPlaceholderName="pageContent" template="" genericContentItemName="" />
<item urlSearchPattern="connections-learning" contentPlaceholderName="pageContent" template="Connections Learning Content Page" genericContentItemName="" />
<item urlSearchPattern="online-high-school" contentPlaceholderName="pageContent" template="" genericContentItemName="" />
</items>
I am trying to find the first node where the urlSearchPattern attribute is contained in the string urlSearchPattern. Where I'm having trouble is finding the nodes where the attribute is contained in the string value instead of the string value be contained in the attribute.
Here's my attempt so far. This will find the firstOrDefault node where the string value is contained in the attribute (I need the opposite)...
string urlSearchPattern = Request.QueryString["aspxerrorpath"];
MissingPageSettingsXmlDocument missingPageSettingsXmlDocument = new MissingPageSettingsXmlDocument();
XmlNode missingPageItem = missingPageSettingsXmlDocument.SelectNodes(ITEM_XML_PATH).Cast<XmlNode>().Where(item => item.Attributes["urlSearchPattern"].ToString().ToLower().Contains(urlSearchPattern)).FirstOrDefault();
When I run the following program:
public static void main(String args[]) throws Exception
{
byte str[] = {(byte)0xEC, (byte)0x96, (byte)0xB4};
String s = new String(str, "UTF-8");
}
on Linux and inspect the value of s in jdb, I correctly get:
s = "ì–´"
on Windows, I incorrectly get:
s = "?"
My byte sequence is a valid UTF-8 character in Korean, why would it be producing two very different results?
My code tries to replace "," with "/" in a string. Should I escape "," in the regex string? Both of the two code snippets generated the same results, so I am confused.
Code snippet 1:
String test = "a,bc,def";
System.out.println(test.replaceAll("\\,", "/"));
Code snippet 2:
String test = "a,bc,def";
System.out.println(test.replaceAll(",", "/"));
Should I use "," or "\,"? Which is safer?
Thanks.
In my Android app, I want to use a single variable for the log name in multiple files. At the moment, I'm specifying it separately in each file, e.g.
public final String LOG_NAME = "LogName";
Log.d(LOG_NAME, "Logged output);
I've tried this:
public final String LOG_NAME = (String) getText(R.string.app_name_nospaces);
And while this works in generally most of my files, Eclipse complains about one of them:
The method getText(int) is undefined
for the type DatabaseManager
I've made sure I'm definitely importing android.content.Context in that file. If I tell it exactly where to find getText:
Multiple markers at this line
- Cannot make a static reference to the non-static method getText(int)
from the type Context
- The method getText(int) is undefined for the type DatabaseManager
I'm sure I've committed a glaringly obvious n00b error, but I just can't see it! Thanks for all help: if any other code snippets would help, let me know.
Should I declare an attribute in a javabean that holds a date value a user types in on an HTML form as a String or Date?
I feel I should declare as a Date, however, since I do server validation on all form data, if the date doesn't validate, when I pass the form bean back to the jsp view for correcting, I lose the date value that the user tried to type in.
If I declare as a String, if the date doesn't validate, I'm able to set the string value in the bean and pass the bean back to the view and the user can see what they incorrectly typed.
But with a String declaration for Date inputs I forsee problems down the road with my DAO. I want to be able to use a DAO utility which generates a prepare statement using setObject.
In my html form I request dates to be mm/dd/yyyy and in DAO i'm using Oracle Date. I can not use hibernate or such, since this is a corporate intranet.
What is the best practice "pattern" I should be following??
Hi all,
I noticed the function Object.factory(char[] className) in D.
But it does not work like I hoped it would work; it does not work ;)
An example:
import std.stdio;
class TestClass
{
override string toString()
{
return typeof(this).stringof; // TestClass
}
};
void main(string[] args)
{
auto i = Object.factory("TestClass");
if (i is null)
{
writeln("Class not found");
}
else
{
writeln("Class string: " ~ i);
}
}
I think this should result in the message: "Class string: TestClass" but it says "Class not found".
Does anybody know why this happens and how I could fix it ?
Or do I need to make my own class factory. For example by make a class with a static array Object[string] classes; with class instances. When I want a new instance I do this:
auto i = (className in classes);
if (i is null)
{
return null;
}
return i.classinfo.create();
During investigation of some problem I found that the reason was unexpected different conversion to string[] of seemingly same input data. Namely, in the code below two commands both return the same two items File1.txt and File2.txt. But conversion to string[] gives different results, see the comments.
Any ideas why is it? This might be a bug. If anybody also thinks so, I’ll submit it. But it would nice to understand what’s going on and avoid traps like that.
# *** WARNING
# *** Make sure you do not have anything in C:\TEMP\Test
# *** The code creates C:\TEMP\Test with File1.txt, File2.txt
# Make C:\TEMP\Test and two test files
$null = mkdir C:\TEMP\Test -Force
1 | Set-Content C:\TEMP\Test\File1.txt
1 | Set-Content C:\TEMP\Test\File2.txt
# This gets just file names
[string[]](Get-ChildItem C:\TEMP\Test)
# This gets full file paths
[string[]](Get-ChildItem C:\TEMP\Test -Include *)
# Output:
# File1.txt
# File2.txt
# C:\TEMP\Test\File1.txt
# C:\TEMP\Test\File2.txt
I'm using a combo box to select an item from a list of 25 items.
The selected item is input in a text box in a comma delimited string. It is updating a list view and showing each item separately by breaking the comma delimited string.
The text box is not visible to users but doing the work in back end. Now I want to remove any item from list view and want it so that the text box containing the comma delimited string should also change and remove that item from the string.
Is it possible?
Let's say I have the following array (which is the returned value of a database query):
Array ( [0] => PHP [1] => Webdesign [2] => Wordpress [3] => Drupal [4])
And the following string:
Working With Wordpress Shortcodes
How can I compare the array with the string to see if the string contains any word stored in the array? (hopefully that made sense to you :d )
When he finds a match (eg: Wordpress) it should create a hashtag like so:
Working With #Wordpress Shortcodes
I have 1 function that I want to return the address of an assigned string to the main function and assign an new string pointer with the same address so that the new string will have the contents of the old string.
For example:
unknown_datatype function()
{
char *old = "THE STRING";
return old;
}
int main()
{
char *snew = "";
snew = function();
return 0;
}
*unknown_datatype means I don't know that to put there...
*How can I approach this without changing anything in the main() method
I am new to Programming languages. I have a requirement where I have to return a record based on a search string.
For e.g. I am having the following 3 records and my search string is 'Cal'
1)University of California
2)Pascal Institute
3)California University
If I try string.Contains, all 3 are returned. If I try string.starts-with, I get only 3 but my requirement is I need #1 and #3 in the result.
Thank you for your help.
-Joel
I have a string which is ultimately the id of a CheckBox.
What I need to be able to do is to access the CheckBox's properties from the string
var myCheckBox:Object;
var myString:String;
myString = "checkbox_1"
myCheckBox = Object(myString); ?!?!
... and then I'd need to get to myCheckBox.selected, and myCheckBox.label etc
How can I check a file for a string if missing the string automatically add it for example
Input
Input file test.txt
this is a test text for testing purpose
this is a test for testing purpose
this is a test for testing purpose
this is a test text for testing purpose
I would like to add "text" to all the lines
Desired Output
this is a test text for testing purpose
this is a test text for testing purpose
this is a test text for testing purpose
this is a test text for testing purpose
Is it possible? many thanks in advance
Hi guys thanks for all the help, for my case is not that simple. I wont know which line will be different and in the middle string it will not only have a single string. i will give a clearer case
Input file test.txt
Group: IT_DEPT,VIP Role: Viewer Dept: IT
Group: IT_DEPT,VIP Dept: IT
Group: FINANCE LOAN VIEWER Role: Viewer Dept: FINANCE
Group: FINANCE LOAN VIEWER Dept: FINANCE
Desired output file test2.txt
Group: IT_DEPT,VIP Role: Viewer Dept: IT
Group: IT_DEPT,VIP Role: - Dept: IT
Group: FINANCE LOAN VIEWER Role: Viewer Dept: FINANCE
Group: FINANCE LOAN VIEWER Role: - Dept: FINANCE
So those that are missing "Role:" will be added "Role: - ", hope this clear things out, thanks in advance again
Hello all,
How do I remove numbers from a string using Javascript?
I am not very good with regex at all but I think I can use with replace to achieve the above?
It would actually be great if there was something JQuery offered already to do this?
//Something Like this??
var string = 'All23';
string.replace('REGEX', '');
I appreciate any help on this.
OK, I've got the code to allow me to index through the string resources. Now, how do I get the value of a specific resource item without knowing its name?
Here's the index loop:
Field[] fLst = R.string.class.getFields();
for(Field f : fLst){
Log.i(dbgTag, "Field Entry: R.string." + f.getName());
}
Thanks for your efforts ...
For every string, I need to print # each 6 characters.
For example:
example_string = "this is an example string. ok ????"
myfunction(example_string)
"this i#s an e#ample #string#. ok ?#???"
What is the most efficient way to do that ?
I have a String array of names, and then I added it into an editable JComboBox.
The user can either pick his/her name from the choices or just input his/her name if not in the choices.
How do I put the user input into a new string variable?
String [] chooseName = { Mark, John, Allison, Jessica };
JComboBox combo = new JComboBox (chooseName);
combo.setEditable(true);
String chosenName = /* how do i place what the user inputed here? */
I have to following code. I want this to return an array e.g. arg[] that contains at arg[0] the number of the rows of my cursor and at arg[1] String(0) of my cursor. Since one is integer and the other is string I have a problem. Any ideas how to fix this?
public String[] getSubcategoriesRow(String id){
this.openDataBase();
String[] asColumnsToReturn = new String[] {SECOND_COLUMN_ID,SECOND_COLUMN_SUBCATEGORIES,};
Cursor cursor = this.dbSqlite.query(SECOND_TABLE_NAME, asColumnsToReturn, SECOND_COLUMN_SUBCATEGORIES + "= \"" + id + "\"", null, null, null, null);
String string = cursor.getString(0);
int count = cursor.getCount();
String arg[] = new String[]{count, string};
cursor.close();
return arg;
}
The cursor and the results and correct i just need to compine them to an array in order to return that.
Say I only need to find out whether a line read from a file contains a word from a finite set of words.
One way of doing this is to use a regex like this:
.*\y(good|better|best)\y.*
Another way of accomplishing this is using a pseudo code like this:
if ( (readLine.find("good") != string::npos) ||
(readLine.find("better") != string::npos) ||
(readLine.find("best") != string::npos) )
{
// line contains a word from a finite set of words.
}
Which way will have better performance? (i.e. speed and CPU utilization)
Need to write a method describePerson() that takes 3 parameters, a String giving a person’s
name, a boolean indicating their gender (true for female, false for male), and an integer giving their age. The method should return a String formatted as in the following examples:
Lark is female. She is 2 years old.
Or
Jay is male. He is 1 year old.
I am not sure how to write it correctly (my code):
int describePerson(String name, boolean gender, int age) {
String words="";
if(gender==true) return (name + "is "+gender+". "+"She is"+age+ "years old.);
else
return (name + "is "+gender+". "+"She is"+age+ "years old.);
}
The outcome "year" and "years" is also differs, but i don't know how to make it correct..
Please, could you answer my question.
How to remove digits from the end of the string using SQL?
For example, the string '2Ga4la2009' must be converted to 2Ga4la. The problem is that we can't trim them because we don't know how many digits are in the end of the string.
Best regards, Galina.