|
text = text.Trim().Replace( "\n\n", "\n" );
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
I think you meant this.
while (text.Contains("\n\n")) {
text = text.Replace("\n\n", "\n");
}
/ravi
|
|
|
|
|
(I think I failed to copy my own code)
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
That only works with completely empty lines. For a production system, you'd want a regex that matches 0 or more space/tab characters between the newlines.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
|
|
|
|
|
text = text.Trim().Replace( "\n\n", "\n" ).Replace("\t", "").Replace(" ", "");
Anything else?
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
That doesn't do what you think it does.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
|
|
|
|
|
Props for trying, but I found out he ain't open to suggestion.
Jeremy Falcon
|
|
|
|
|
You'd want something more like this: /^\s*?(?:\r\n|\r|\n)\s*?$/gm . Notice the global modifier, it will help with the newline side of things for the second line.
Jeremy Falcon
|
|
|
|
|
Mine works ... and I can read it.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Yours works only in a very specific circumstance for something you find useful. Yours will leave any extra whitespace and make no distinction between a blank line or line with whitespace. This also means yours cannot be automated.
So, you're welcome.
Jeremy Falcon
|
|
|
|
|
a trivial AWK program would do the trick . or you can utilize regular expressions Find/Replace though i am still uncertain how to handle end of line and new line but am certain it can be done as i have been successful in past though i do not recall the details . a little learning experimentation will no doubt do the trick .
|
|
|
|
|
Props for mentioning regex. Most devs never take the time to learn it, but it's an extremely useful tool.
Jeremy Falcon
|
|
|
|
|
AI is often used where simple if/then's are perfectly appropriate.
But: If you integrate an AI solution then you don't just get an overblown whitespace remover, you open yourself to formatting, syntax checking, code completion, and lots of other stuff that AI is actually great at.
cheers
Chris Maunder
|
|
|
|
|
Every developer should take the time to learn regex. Most of the pesky grep-type problems have already been solved. Besides, AI is too busy focusing on ruling the world.
Jeremy Falcon
|
|
|
|
|
Check the title.
Jeremy Falcon
|
|
|
|
|
Certainly better to use AI for that rather than rely on something that actually mattered.
|
|
|
|
|
You seem like the sort who would use a Nutrimatic machine to simply boil dried leaves.
|
|
|
|
|
|
|
|
Those of you that are familiar with sqlxml (particularly FOR XML EXPLICIT) may know it's a series of joins with coded column names representing the attributes for each element, and keyed to a parent to nest.
Column names look like this:
Tag Parent employee!1!employeeID customer!2!customerID customer!2!region
FOR XML EXPLICIT[^] for details.
Anyway, a long time ago a friend and I collaborated for work on a generalized SQLXML layer over any oledb source, not just SQL Server. It worked great.
And later I started on generalizing *that* to work on any sort of rowset, not just databases.
Such that you can (without oledb) craft a .csv for example using FOR XML EXPLICIT rules and get a reproduction of it in XML, or turn XML into a flat CSV.
CSV is just an example. Really anything implementing IEnumerable<IDataRow> or something.
The trouble is, it's a lot of work and I'm not sure if there would be any interest in such a thing these days.
It has been a long time since I've touched bizdev.
If you're interested, can you indicate it through a response emoji or letting me know in replies? If I get enough of it that it compels me then I'll write the article and the code.
To err is human. Fortune favors the monsters.
modified 30-Apr-23 2:05am.
|
|
|
|
|
I think more people are using JSON over XML now.
If you support both, you might draw more interest.
|
|
|
|
|
I was considering that, but I didn't want to promise it until I try it.
To err is human. Fortune favors the monsters.
|
|
|
|
|
Yes, except no, I already roll my own.
One utility I have is a fairly simple ETL tool which can read data from a number of disparate (tabular) sources (e.g. CSV, SQL Server, LDAP, SPLUNK, XML) and write it to a number of disparate (tabular) destinations (e.g. CSV, SQL Server, XML).
I have plans to add reading and writing JSON, but I have been putting it off.
Every type of source returns an IDataReader and every type of destination reads from an IDataReader.
There is some amount of flexibility for specifying the schema of the IDataReader, but not a lot.
The XML I produce is probably not what you would want though, and I don't have it configurable.
I would be interested in what you envision as a way of specifying the schema of the XML to produce.
|
|
|
|
|
PIEBALDconsult wrote: I would be interested in what you envision as a way of specifying the schema of the XML to produce.
That's where a lot of that work I was talking about comes in.
On that run where we did it, maybe back in 2004 or 2005, we used annotated XSD (XML Schema) and recognized mapping annotations that wherever we could, were already defined by microsoft.
So if you actually plug in a schema it can generate those column names I mentioned for you, or conversely, take tabular data and XMLize it.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:element name="Contact" sql:relation="Person.Contact" >
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FName"
sql:field="FirstName"
type="xsd:string" />
<xsd:element name="LName"
sql:field="LastName"
type="xsd:string" />
</xsd:sequence>
<xsd:attribute name="ConID"
sql:field="ContactID"
type="xsd:integer" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
And when we needed additional annotations we just added another namespace with more attributes defined in it, like microsoft did with the "msdata" namespace (that's just the prefix, i forget the URN)
or, alternatively, if you're going the explicit route you can make your csv field a nested element it would be like employee!1!employeeID!element instead of just employee!1!employeeID
One problem you'll find with JSON, is while XML makes sparse use of "arrays" in xml attributes, JSON basically uses arrays in its fields everywhere. When you go to map that to relational data, you'll have to come up with a scheme probably to pack subitems into a field using a join, and it will make your rowset significantly bigger breaking it out like that, but the alternative is denormalizing into a delimited list, if that makes sense. That might be tricky with JSON because you lose normalization of any nested objects.
Also remember arrays are ordered but fields are not in JSON.
Aside from that, less datatypes, but in some ways that makes it easier.
If you want to support JSON schema it's going to be quite difficult, but then so is XSD, because they're both lexically oriented rather than data oriented.
To err is human. Fortune favors the monsters.
|
|
|
|