Does Python have a pool of all strings and are they (strings) singletons there?
More precise, in the following code one or two strings were created in memory:
a = str(num)
b = str(num)
?
I'm using a PropertyGrid to display a property. For one property, I'm displaying strings in a drop-down combobox. The displayed text of the property and the value of the property are both strings, but their text is different. The displayed text is friendly, the value text corresponds to a registry key name. I've created a TypeConverter to convert between the display text and the value text, but the ConvertFrom() method appears to work correctly until I change the combo-box selection. It then sends the 'value' text instead of the display text to use during the conversion.
Has anyone else used string-to-string conversion successfully?
Hi,
I'm using LINQ to Entities on a database which structure is not known in advance. I use reflection to retrieve the information, and now have a list of strings with all the table names. Because I use LINQ, I also have the datasource encapsulated in a C# class (linqContext), with each table being a property of that class.
What I want to achieve is this:
Assume one of the strings in the table names list is "Employees". This is known in code, I want to do the following:
linqContext.Employees.DoSomethingHere();
Is this possible? I know that if all the propertie were just items in a list, I could use the string as indexer, linqContext["Employees"]. However, this is not the case :(
Spent some time troubleshooting a problem whereby a PHP/MySQL web application was having problems connecting to the database. The database could be accessed from the shell and phpMyAdmin with the exact same credentials and it didn't make sense.
Turns out the password had a $ sign in it:
$_DB["password"] = "mypas$word";
The password being sent was "mypas" which is obviously wrong.
What's the best way to handle this problem? I escaped the $ with a \
$_DB["password"] = "mypas\$word";
and it worked.
I generally use $string = 'test' for strings which is probably how I avoided running into this before.
Is this correct behavious? What if this password was stored in a database and PHP pulled it out - would this same problem occur? What am I missing here...
Hi,
I would like to know if anyone has info or experience on how to do something which sounds simple but doesn't look like it when trying to program it.
The idea is : give a string containing an equation, such as : "2*x = 10" for example (this is simple, but it could get very complex, such as sqrt(54)*35=x^2; and so on....) and the program would return x = 5 and possibly give a log of how he got there.
Is this doable ? If so, does anyone have a lead ? For info there is this site (http://www.numberempire.com/equationsolver.php) which does the same thing in PHP, but isn't open source.
Thanks for any help !
Hello everyone.
I'll cut right to the chase. Right now I am developing a web based application. It has a PHP REST based architecture that serves up XML documents. On many of these documents attributes are hex encoded picture strings.
On the client side jQuery AJAX fetches an XML document with a picture in it. I need to display said picture in some <img> tags. However my knowledge on such methods is lacking so here I am asking for help.
Goal:
JavaScript String variable in hex or base64 HTML displayed image.
Cross browser is required, or a hack for the ones that do not support it is fine.
Thanks,
Gunnar
I just found a weird behaviour when attempting to extract a string from the Binary-table in the MSI.
I have a file containing "Hello world", the data I get is "???Hello world". (Literary question mark.)
Is this as intended?
Will it always be exactly 3 characters in the beginning?
Regards
Leif
Sample code:
[CustomAction]
public static ActionResult CustomAction2(Session session)
{
View v = session.Database.OpenView("SELECT `Name`,`Data` FROM `Binary`");
v.Execute();
Record r = v.Fetch();
int datalen = r.GetDataSize("Data");
System.IO.Stream strm = r.GetStream("Data");
byte[] rawData = new byte[datalen];
int res = strm.Read(rawData, 0, datalen);
strm.Close();
String s = System.Text.Encoding.ASCII.GetString(rawData);
// s == "???Hello World"
return ActionResult.Success;
}
I'm trying to call the jQuery text() function and run it through the trim() function to remove all trailing and leading whitespace. Seems to work great in Firefox, however, does not work in IE7 (refuses to remove a space trailing at the end).
Any ideas?! Maybe a regex solution?
I'm developing an ASP.NET MVC application in which I want to encrypt a short string on the server, using C#, and send it to the client-side.
Then on the client-side it will be decrypted through Javascript code.
Any thoughts on how to implement this?
Do you know of a simple encryption algorithm (doesn't have to be bullet-proof secure) that can be easily translated from C# to Javascript or vice-versa?
NOTE: I could do this entirely in C# and do the decryption through Ajax, but I'd prefer not to do it this way, as I want to reduce website traffic as much as possible.
this is my code -
With ad.Tables(2)
For i As Integer = 0 To .Rows.Count - 1
If .Rows(i)("name") & "" <> "" Then
temp &= .Rows(i)("name") & ", "
End If
Next
End With
temp = temp.Trim(",")
testing &= "&Name=" & temp & vbCrLf
with this is get a comma in the end of the string. but if i do this
temp = temp.Trim.Trim(",")
all commas are deleted.
How do i keep all commas and only delete the last one?
I have following problem,
Code:
String a="Yeahh, I have no a idea what's happening now!";
System.out.println(a);
a=a.replaceAll("a", "");
System.out.println(a);
Before removing 'a', result:
Yeahh, I have no a idea what's happening now!
Actual Result:
After removing 'a', result:
Yehh, I hve no ide wht's hppening now!
Desired Result:
Yeahh, I have no idea what's happening now!
Anyone can gimme some advices to achieve my desired result?
Given this :
import os
import subprocess
def check_server():
cl = subprocess.Popen(["nmap","10.7.1.71"], stdout=subprocess.PIPE)
result = cl.communicate()
print result
check_server()
check_server() returns this tuple:
('\nStarting Nmap 4.53 ( http://insecure.org ) at 2010-04-07 07:26 EDT\nInteresting ports on 10.7.1.71:\nNot shown: 1711 closed ports\nPORT STATE SERVICE\n21/tcp open ftp\n22/tcp open ssh\n80/tcp open http\n\nNmap done: 1 IP address (1 host up) scanned in 0.293 seconds\n', None)
Changing the second line in the method to
result, err = cl.communicate()
results in check_server() returning :
Starting Nmap 4.53 ( http://insecure.org ) at 2010-04-07 07:27 EDT
Interesting ports on 10.7.1.71:
Not shown: 1711 closed ports
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 0.319 seconds
Looks to be the case that the tuple is converted to a string, and the \n's are being stripped.... but how? What is 'err' and what exactly is it doing?
I have a program that reads arbitrary data from a file system and outputs results in Unicode. The problem I am having is that sometimes filenames are valid Unicode and sometimes they aren't. So I want a function that can validate a string (in C or C++) and tell me if it is a valid UTF-8 encoding. If it is not, I want to have the invalid characters escaped so that it will be a valid UTF-8 encoding. This is different than escaping for XML --- I need to do that also. But first I need to be sure that the Unicode is right.
I've seen some code from which I could hack this, but I would rather use some working code if it exists.
How can I parse a strings like :
name1="val1" name2="val2" name3="val3"
I cannot use split(\s+) as it can be name = "val 1".
I am doing java but any laguage is okay.
Every time I have to split a long string literal into two (or more) pieces, because it does not fit into a single line, I have to decide if I split the text before or after a space.
For example:
const char * long_text1 = "This is a long text, which does not fit "
"in one line";
/* or */
const char * long_text2 = "This is a long text, which does not fit"
" in one line";
I tend to use the first way, but I do not have a real reason for it. So I wonder is there any advantage to favor one of them? I know this questions tend to be coding style question, but that's not my intend. I only want to know if there is a convincing reason why one of those two ways might be preferable.
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);
In C, I have format strings, something like:
char *msg = "wlll you marry me"
fprintf(stderr, "%s, %s?", name, msg);
Now, can I do something similar in lua with format strings? I.e. I want something functionally equivalent to:
name .. ", " .. msg .. "?"
but not so ugly, in lua.
Okay, so I can do string.format("%s, %s?", name, msg), but can I go even a step further, something like perl style, where I can go:
"%name, %msg?"
Thanks!
need some help with building a powershell script to help with some basic string manipulation. I know just enough powershell to get in trouble, but can't figure out the syntax or coding to make this work.
I have a text file that looks like this -
Here is your list of servers:
server1
server2.domain.local
server3
Total number of servers: 3
I need to take that text file and drop the first and last lines (Always first and last.) Then I need to take every other line and basically turn it into a CSV file.
The final output should be a text file that looks like this -
server1,server2.domain.local,server3
Any suggestions on where to start? Thanks!
In SQL we can see if a string is in a list like so:
Column IN ('a', 'b', 'c')
What's a good way to do this in javascript? I realize one can use the switch function:
var str = 'a'
var flag = false;
switch (str) {
case 'a':
case 'b':
case 'c':
flag = true;
default:
}
if (thisthing || thatthing || flag === true) {
// do something
}
But this is a horrible mess. It's also clunky to do this:
if (thisthing || thatthing || str === 'a' || str === 'b' || str = 'c') {
// do something
}
And I'm not sure about the performance or clarity of this:
if (thisthing || thatthing || {a:1, b:1, c:1}[str]) {
// do something
}
Any ideas?
In my last question I asked about parsing the links out of an HTML page. Since I haven't found a solution yet I thought I tried something else in the meantime: search for every <a href= and copy whatever is there until I hit a </a>.
Now, my C is a bit rusty but I do remember i can use strstr() to get the first instance of that string, but how do I get the rest?
Any help is appreciated.
PS: No. This is not homework on school or something like that. Just so you know.
I have a 'Contact' class with two properties : firstName and lastName.
When I want to display a contact's full name, here is what I do:
NSString *fullName = [NSString stringWithFormat:@"%@ %@", contact.firstName, contact.lastName];
But when the firstName and/or lastName is set to nil, I get a "(null)" in the fullName string. To prevent it, here's what I do:
NSString *first = contact.firstName;
if(first == nil) first = @"";
NSString *last = contact.lastName;
if(last == nil) last = @"";
NSString *fullName = [NSString stringWithFormat:@"%@ %@", first, last];
Does someone know a better/more concise way to do this?
hi all,
I'm making a http get request like this:
try {
HttpClient client = new DefaultHttpClient();
String getURL = "http://busspur02.aseag.de/bs.exe?SID=5FC39&ScreenX=1440&ScreenY=900&CMD=CR&Karten=true&DatumT="+day+"&DatumM="+month+"&DatumJ="+year+"&ZeitH="+hour+"&ZeitM="+min+"&Intervall=60&Suchen=(S)uchen>0=Aachen&T0=H&HT0="+start_from+">1=Aachen&T0=H&HT1="+destination+"";
HttpGet get = new HttpGet(getURL);
HttpResponse responseGet = client.execute(get);
HttpEntity resEntityGet = responseGet.getEntity();
if (resEntityGet != null) {
//do something with the response
Log.i("GET RESPONSE",EntityUtils.toString(resEntityGet));
}
........
It all works well... the only problem: the output from Log.i is cut-off... It's not the complete html page. If I make the same request in a browser, I get 3x the output in opposition to making the request in the emulator and using the above code.... what's wrong?
I have a legacy VB6 app where the servername, databasename, username, etc are defined in an INI file, but the port number for the connection string (the default 1433) is hard coded in the app. It's being moved to a new sql server back end that runs off a different port number. I'm trying to avoid having to alter and recompile the application which entails signifigant retesting, documentation, etc. I tried altering the INI file so that for the new server I have put in: SERVERNAME\INSTANCE,NEWPORTNUMBER
This effectively builds the connection with Data Source = SERVERNAME\INSTANCE,NEWPORTNUMBER,1433;
This appears to work correctly as it connects to the database when I run the app. It appears to me that the ,1433 portion is being ignored. Is this a valid assumption or will this cause me some problem I'm not seeing here?
I've got some very basic code like
while (scan.hasNextLine())
{
String temp = scan.nextLine();
System.out.println(temp);
}
where scan is a Scanner over a file.
However, on one particular line, which is about 6k chars long, temp cuts out after something like 2470 characters. There's nothing special about when it cuts out; it's in the middle of the word "Australia." If I delete characters from the line, the place where it cuts out changes; e.g. if I delete characters 0-100 in the file then Scanner will get what was previously 100-2570.
I've used Scanner for larger strings before. Any idea what could be going wrong?
Hi,
I have a need to support extensive auditing capabilities for a system backing into Sql Server 2008. Since I plan to use LINQ (with no Stored Procs), the database would be a clean, zero contact data repository.
However, I need to pratically record a snapshot of every change that happens in the db. So, I thought I should use triggers. But then, I need a user id for the particular user (not the connection string user id) to flow through into the database.
In oracle, I should have been able to set up a PROXY USER and the trigger would be able to pick that up. Last I checked, there was no proxy user concept in Sql Server.
Does anyone know if there's any extender property I can use to flow through my authenticated user name?
ps: I don't mind the impact on connection pooling (if any).
Thanks.
P