ABCDchinchwad18-Mar-2010-11.sql.zip
ABCDsolapur18-Mar-2010-10.sql.zip
How do I find the string between "ABCD" and the date "18-Mar-2010"
Expected resuts:
chinchwad
solapur
Hi StackOverflow,
I have a Java application that makes heavy use of a large file, to read, process and give through to SolrEmbeddedServer (http://lucene.apache.org/solr/).
One of the functions does basic HTML escaping:
private String htmlEscape(String input)
{
return input.replace("&", "&").replace(">", ">").replace("<", "<")
.replace("'", "'").replaceAll("\"", """);
}
While profiling the application, the program spends roughly 58% of the time in this function, a total of 47% in replace, and 11% in replaceAll.
Now, is the Java replace that slow, or am I on the right path and should I consider the program efficient enough to have its bottleneck in Java and not in my code? (Or am I replacing wrong?)
Thanks in advance!
I've read through a few threads detailing how to tokenize strings, but I'm apparently too thick to adapt their suggestions and solutions into my program. What I'm attempting to do is tokenize each line from a large (5k+) line file into two strings. Here's a sample of the lines:
0 -0.11639404
9.0702948e-05 0.00012207031
0.0001814059 0.051849365
0.00027210884 0.062103271
0.00036281179 0.034423828
0.00045351474 0.035125732
The difference I'm finding between my lines and the other sample input from other threads is that I have a variable amount of whitespace between the parts that I want to tokenize. Anyways, here's my attempt at tokenizing:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
ifstream input;
ofstream output;
string temp2;
string temp3;
input.open(argv[1]);
output.open(argv[2]);
if (input.is_open())
{
while (!input.eof())
{
getline(input, temp2, ' ');
while (!isspace(temp2[0])) getline(input, temp2, ' ');
getline (input, temp3, '\n');
}
input.close();
cout << temp2 << endl;
cout << temp3 << endl;
return 0;
}
I've clipped it some, since the troublesome bits are here. The issue that I'm having is that temp2 never seems to catch a value. Ideally, it should get populated with the first column of numbers, but it doesn't. Instead, it is blank, and temp3 is populated with the entire line. Unfortunately, in my course we haven't learned about vectors, so I'm not quite sure how to implement them in the other solutions for this I've seen, and I'd like to not just copy-paste code for assignments to get things work without actually understanding it. So, what's the extremely obvious/already been answered/simple solution I'm missing? I'd like to stick to standard libraries that g++ uses if at all possible.
I've been fiddling with this for over twenty minutes and my Google-foo is failing me.
Let's say I have an XML Document created in Java (org.w3c.dom.Document):
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document document = docBuilder.newDocument();
Element rootElement = document.createElement("RootElement");
Element childElement = document.createElement("ChildElement");
childElement.appendChild(document.createTextNode("Child Text"));
rootElement.appendChild(childElement);
document.appendChild(rootElement);
String documentConvertedToString = "?" // <---- How?
How do I convert the document object into a text string?
I have a method that finds all the controls, iterates through them, determines if they are a textbox,drop down list, etc.. retrieves their ID name, and depending on the ID name it will set a boolean statement (thus I would know if that section of the form is complete, and will email to a certain group of people) unfortunetly this is done with too many if statements and was wondering if I could get some help making this more manageable
` protected void getEmailGroup()
{
Control[] allControls = FlattenHierachy(Page);
foreach (Control control in allControls)
{
if (control.ID != null)
{
if (control is TextBox)
{
TextBox txt = control as TextBox;
if (txt.Text != "")
{
if (control.ID.StartsWith("GenInfo_"))
{
GenInfo = true;
}
if (control.ID.StartsWith("EmpInfo_"))
{
EmpInfo = true;
}
}
}
if (control is DropDownList)
{
DropDownList lb = control as DropDownList;
if (lb.SelectedIndex != -1)
{
if (control.ID.StartsWith("GenInfo_"))
{
GenInfo = true;
}
if (control.ID.StartsWith("EmpInfo_"))
{
EmpInfo = true;
}
}
}
}
}
}`.
Hello,
I have a database (sql 2008 mdf file), a class library project with an edmx file, created with the wizard. So the connection string is also made by the wizard.
This project is on a teamfoundation server.
I can use all the wizard made objects when coding.
But when i run the program and I try to make an entityContainerName, the program crashes and gives this error:
The specified named connection is
either not found in the configuration,
not intended to be used with the
EntityClient provider, or not valid.
on this line:
public TestEntities() : base("name=TestEntities", "TestEntities")
How can I solve this problem or what am I doing wrong?
Hello, I need help sorting and counting instances of the words in a string.
Lets say I have a collection on words:
happy beautiful happy lines pear gin happy lines rock happy lines pear
How could I use php to count each instance of every word in the string and output it in a loop:
There are $count instances of $word
So that the above loop would output:
There are 4 instances of happy.
There are 3 instances of lines.
There are 2 instances of gin....
Thank you for your genius.
<ListBox x:Name="MainList" HorizontalAlignment="Left" Height="468" Margin="10,10,0,0" VerticalAlignment="Top" Width="100" ItemsSource="{Binding Items,Mode=TwoWay}" DisplayMemberPath="Name"/>
[Serializable()]
public class MYcontainer : INotifyPropertyChanged,ISerializable
{
private List<MYClass> _items = new List<MYClass>();
public List<MYClass> Items
{
get{ return _items;}
set { this._items =value;
OnPropertyChanged("Items");
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName = null)
{
var eventHandler = this.PropertyChanged;
if (eventHandler != null)
eventHandler(this, new PropertyChangedEventArgs(propertyName));
}
}
when i add an item to "Items" the UI doesnt update, the binding is working fine, since if i closed the window and opened it again, the new items appear correctly
what am i doing wrong? i know if i used observablecollection it will work fine, but shouldn't it work with List<? , i already have in another window a string[] property and it update fine
I am running Exchange 2013 on Windows Server 2012 R2.
When I add my exchange account to Outlook, it seems to work perfectly (sending/receiving email, syncing everything), but when I open the account settings it has the following set as the Server:
[email protected]
I would have expects this to be: mail.domain.com since this is the DNS A record pointing to the IP of my server. Where is it getting this server name?
I have a string like so
item[3]>something>another>more[1]>here
hey>this>is>something>new
.
.
.
I would like to produce the following for each iteration indicated by each new line
item[3]>something>another>more[1]>here
something>another>more[1]>here
another>more[1]>here
more[1]>here
here
Another example:
hey>this>is>something>new
this>is>something>new
is>something>new
something>new
new
I would like a regex or some way to incrementally remove the furthest left string up to .
I'm working on a string pattern match algorithm. I use NSRegularExpression for finding the matches. For ex: I've to find all words starting with '#' in a string..
Currently I use the following regex function:
static NSRegularExpression *_searchTagRegularExpression;
static inline NSRegularExpression * SearchTagRegularExpression()
{
if (!_searchTagRegularExpression)
{
_searchTagRegularExpression = [[NSRegularExpression alloc]
initWithPattern:@"(?<!\\w)#([\\w\\._-]+)?
options:NSRegularExpressionCaseInsensitive error:nil];
}
return _searchTagRegularExpression;
}
and I use it as below:
NSRegularExpression *regexp = SearchTagRegularExpression();
[regexp enumerateMatchesInString:searchString
options:0 range:stringRange
usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop)
{
// comes here for every match with range
}];
This works properly. But i just want to know if this is the best way. suggest if there's any better alternative...
Please see this piece of code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main() {
int i = 0;
FILE *fp;
for(i = 0; i < 100; i++) {
fp = fopen("/*what should go here??*/","w");
//I need to create files with names: file0.txt, file1.txt, file2.txt etc
//i.e. file{i}.txt
}
}
I have an column declarated as int (called HourMil) wich store the time in military format. i need convert this values to an formated string (HH:MM)
example
HourMil = 710 -> must be 07:10
HourMil = 1305 -> must be 13:05
Actually i am using this code (and works ok) for convert the column HourMil to the string representation.
SELECT SUBSTRING(LEFT('0',4-LEN(CAST(HourMil AS VARCHAR)))+CAST(HourMil AS VARCHAR),1,2)+':'+SUBSTRING(LEFT('0',4-LEN(CAST(HourMil AS VARCHAR)))+CAST(HourMil AS VARCHAR),3,2) FROM MYTABLE
but I think this code can be improved.
Hello,
In the following XML structure how do i retrieve the name value and put this into a string?
(i am using a XPathNavigator in my method)
<testsystem>
<test>
<name>one</name>
</test>
</testsystem>
I was able to get a attribute with a syntax alike this: (but when changing the xml struture it no longer holds a attribute value)
string name = nav.GetAttribute("name", "")
But have no luck getting the value with a nav as of yet.
The purpose is to be able to use it for the following object so i can put name into it.
test t = new test() { Name = name, Questions= new List<Questions>() };
Best regards.
Have an image field and want to insert into this from a hex string:
insert into imageTable(imageField)
values(convert(image, 0x3C3F78...))
however when I run select the value is return with an extra 0 as 0x03C3F78...
This extra 0 is causing a problem in another application, I dont want it.
How to stop the extra 0 being added?
The schema is:
CREATE TABLE [dbo].[templates](
[templateId] [int] IDENTITY(1,1) NOT NULL,
[templateName] [nvarchar](50) NOT NULL,
[templateBody] [image] NOT NULL,
[templateType] [int] NULL)
and the query is:
insert into templates(templateName, templateBody, templateType)
values('I love stackoverflow', convert(image, 0x3C3F786D6C2076657273696F6E3D.......), 2)
the actual hex string is quite large to post here.
I have a method that finds all the controls, iterates through them, determines if they are a textbox,drop down list, etc.. retrieves their ID name, and depending on the ID name it will set a boolean statement (thus I would know if that section of the form is complete, and will email to a certain group of people) unfortunetly this is done with too many if statements and was wondering if I could get some help making this more manageable
protected void getEmailGroup()
{
Control[] allControls = FlattenHierachy(Page);
foreach (Control control in allControls)
{
if (control.ID != null)
{
if (control is TextBox)
{
TextBox txt = control as TextBox;
if (txt.Text != "")
{
if (control.ID.StartsWith("GenInfo_"))
{
GenInfo = true;
}
if (control.ID.StartsWith("EmpInfo_"))
{
EmpInfo = true;
}
}
}
if (control is DropDownList)
{
DropDownList lb = control as DropDownList;
if (lb.SelectedIndex != -1)
{
if (control.ID.StartsWith("GenInfo_"))
{
GenInfo = true;
}
if (control.ID.StartsWith("EmpInfo_"))
{
EmpInfo = true;
}
}
}
}
}
}
I have one TextBox and One listbox for searching a collection of data. While searching a text inside a Listbox if that matching string found in anywhere in the list it should show in Green color with Bold.
eg. I have string collection like
"Dependency Property, Custom Property, Normal Property" if i type in the Search Text box "prop" all the Three with "prop" (only the word Prop) should be in Bold and its color should be in green. any idea how it can be done?.
Data inside listbox is represented using DataTemplate.
I have large text files with space delimited strings (2-5). The strings can contain "'" or "-". I'd like to replace say the second space with a pipe. What's the best way to go?
Using sed I was thinking of this:
sed -r 's/(^[a-z'-]+ [a-z'-]+\b) /\1|/' filename.txt
Any other/better/simpler ideas?
Thank you
I've looked at the other ruby/encoding related posts but haven't been able to figure out why the following is not working. Likely just because I'm dense, but here's the situation.
Using Ruby 1.9 on windows. I have a set of CSV files that need some data appended to the end of each line. Whenever I run my script, the appended characters are gibberish. The input text appears to be IBM437 encoding, whereas my string I'm appending starts as US-ASCII. Nothing I've tried with respect to forcing encoding on the input strings or the append string seems to change the resultant output. I'm stumped. The current encoding version is simply the last that I tried.
def append_salesperson(txt, salesperson)
if txt.length > 2
return txt.chomp.force_encoding('US-ASCII') + %(, "", "", "#{salesperson}")
end
end
salespeople = Hash[
"fname", "Record Manager"]
outfile = File.open("ActData.csv", "w:US-ASCII")
salespeople.each do | filename, recordManager |
infile = File.open("#{filename}.txt")
infile.each do |line|
outfile.puts append_salesperson(line, recordManager)
end
infile.close
end
outfile.close
I need to be able to take a javascript string, compress it using any fast and available means and get back a binary string/blob.
Background:
The extension I'm developing needs to send various large content to my server.
It does this conveniently by dynamically creating a form, adding fields to the form and posting it. Some of these fields are just too big bandwidth wise for multiple use. I'd like to be able to compress them before adding them and then maybe base64'ing them if the characters cause a problem in the message. Any ideas?
I could use nsiZipWriter with temporary files on disk but that is quite ugly and probably sluggish.
Hi,
I have a product database and I am displaying trying to display them as clean URLs, below is example product names:
PAUL MITCHELL FOAMING POMADE (150ml)
American Crew Classic Gents Pomade 85g
Tigi Catwalk Texturizing Pomade 50ml
What I need to do is display like below in the URL structrue:
www.example.com/products/paul-mitchell-foaming-gel(150ml)
The problem I have is I want to do the following:
Remove anything with braquets(and the braquets)
Remove any numbers next to g or ml e.g. 400ml, 10g etc...
I have been banging my head trying different string replaces but cant get it right, I would really appreciate some help.
Cheers