|
What happens if the first "word" is greater than length N?
If you're just trying to "wrap text", use a text block / box with "text wrapping" set to "on". It will even split words, add ellipses if you want.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi Gerry
Well my guess is that the word would be either Finish or Polish which is the only two languages I know of, who can use up a pencil writing "Hello how are you"
But I get your point Normally I do split at about 60 chars, and it's in 99% of the cases english language I split, so I newer gave it any thought what would happen if the first word was longer than N, but clearly the regex would fail and just return the whole word without splitting.
No I'm not trying to wrap text, I use the splitter to ad text to documents with a max width.
And I could just use split at N, but doing that could split a word in the middle, and that I don't want.
/LR
|
|
|
|
|
I do a lot of "splitting", using ".IndexOf" and ".LastIndexOf", with or without starting offsets. My "brutish" techniques have shown no performance issues, even when splitting (and presenting) thousands of (query) results at a time.
The splitting usually involves chopping off and rereading the chopped item while length > 0. Sounds inefficient but isn't.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi Gerry
That could be another way of doing it.
/LR
|
|
|
|
|
Hmm
So I came up with this
string splittSet = "";
string test_pattern = @"(.{1,60})(\s{1,2}|$)";
RegexOptions regexOptions = RegexOptions.None;
Regex splitText = new Regex(test_pattern, regexOptions);
string inputData = @"The wolf is thought to be an ice age survivor, dating wolves around 300,000 years ago. The wolf is accepted to be the ancestor of the domestic dog as the wolf is thought to have selectively bred in order to breed appealing traits typical of puppies and to eliminate the not so appealing traits of adult wolves.";
foreach (Match match in splitText.Matches(inputData))
{
if (match.Success)
{
splittSet += match.Groups[0].Value + "\n\r";
}
}
Definitely not not as elegant as my original regex, but it seems to work :/ though I do hope that someone have a better/more elegant way of doing it
/LR
|
|
|
|
|
splittSet += match.Groups[0].Value + "\n\r";
Use a StringBuilder class ... one of the most obvious things they ask in interviews.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi Gerry
Some thing like this?
string splitPatteren = @"(.{1," + count + @"})(\s{1,2}|$)";
RegexOptions regexOptions = RegexOptions.IgnoreCase;
Regex splitText = new Regex(splitPatteren, regexOptions);
StringBuilder result = new StringBuilder();
foreach (Match match in splitText.Matches(input))
{
if (match.Success)
{
result.Append(match.Groups[0].Value + delm);
}
}
|
|
|
|
|
Use .AppendLine([...]) if you want to add a (OS independent) "line feed".
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi Gerry
I made the method so the "split delimitre" can be changed at call, default is \n\r but if I should had use for a long string separated by | or some thing else I now have the option to do that.
But else the AppendLine would had been my choice also
/LR
|
|
|
|
|
I'm getting load report failed error while generating report from my IIS published web application.
I'm using visual studio 2015,crystal service pack 20 and Dot net framework 4. Once i get this error i restart my web application from IIS and its works normal. I also disposed my report object and set it to null.
modified 24-Jan-20 4:20am.
|
|
|
|
|
If you look in the event log using Event Viewer, you should get a more detailed report about what has gone wrong. As a practice, it's normally a good idea to log any exceptions in your application as well. These can be used to track down what is going wrong.
|
|
|
|
|
|
I want to communicate with Graphdata from C# Core. Because our graphdata is stored on AWS . In order to access the same i want some solutions
|
|
|
|
|
anil150875 wrote: graphdata Does it have an API?
anil150875 wrote: AWS That has an api.
I'm not sure how to be any more specific. Maybe you can be more specific on what you need?
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
The thing is We have done complete development in PHP . And wants to use here MAP API to track location . I don't know how PHP will communicate with Neptune Graphdata in AWS.
So we are considering Gramlin queries
|
|
|
|
|
Hy everybody,
i have an little app that communicate with an CAS Server. When i'm successful logged in, i get an CAS ticket.
Is it possible to share this login (also contains an jsessionid) with the internet explorer or edge?
Has anybody an C# example for me.
thanks.
|
|
|
|
|
Hallo zusammen,
ich weiß nicht ob ich hier richtig bin.
Ich habe eine einfache Anwendung.
D.h. ein Dialogfenster welches ich bei Bedarf horizontal größer oder kleiner schalten will.
Im Dialogfenster ist ein Bereich (Mitte) vorhanden der bei Bedarf zugeklappt werden soll.
Die Steuerelemente im unteren Bereich (Ein Label und 2 TextBoxen) sollen nach dem
Zuklappen noch sichtbar sein, d.h. immer sichtbar bleiben.
Geht das auf einfache Weise oder muss ich das in umständlicher Weise erledigen?
1. Steuerelemente ausblenden.
2. Dialogfenster auf gewünschte Größe bringen.
3. Steuerelemente im unteren Bereich neu positionieren und wieder einblenden.
Ich hätte sogar ein Bild von meinem Dialog, bloß weiß ich nicht wie man
diesen hochladen kann.
Vielen Dank.
CopWorker
Google Translate: I don't know if I'm right here.
I have a simple application.
That a dialog window which I want to switch horizontally larger or smaller if necessary.
In the dialog window there is an area (center) that should be closed if necessary.
The controls in the lower area (one label and 2 text boxes) should be after the
Collapse still visible, i.e. always remain visible.
Is it easy or do I have to do it in a cumbersome way?
1. Hide controls.
2. Bring the dialog window to the desired size.
3. Reposition the controls in the lower area and show them again.
I would even have a picture of my dialogue, just I don't know how to do it
can upload it.
Thank you very much.
CopWorker
|
|
|
|
|
If you use WPF, then you can use an "Expander" control to hide / show a group of controls. With the Window set to "auto size", that can resize too.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Message Removed
modified 23-Jan-20 4:49am.
|
|
|
|
|
I have a serialized collection of objects, such as
GroupEntity
- ConfigEntity
- DefinitionEntity
- ConfigEntity
- DefinitionEntity
- ConfigEntity
- DefinitionEntity
GroupEntity
- ConfigEntity
- DefinitionEntity
- ConfigEntity
- DefinitionEntity
- ConfigEntity
- DefinitionEntity
Given a generic type parameter T, how would you extract all items from the list for that type? So, if I have a class
public class Parser<T>
{
public T Data { get; set; }
public void LoadDataFromFile(string fileName)
{
List<GroupEntity> allData = Serialization.DeSerializeObject<List<GroupEntity>>(fileName);
Type parameterType = typeof(T);
}
}
and I instantiated it as
var parser = new Parser<ConfigEntity>();
parser.LoadDataFromFile(fileName);
or
var parser = new Parser<DefinitionsEntity>();
parser.LoadDataFromFile(fileName);
This should then extract ONLY the type of entities into the Data property defined by the generic parameter.
I could write some looping code, but I would then need conditional code for each type. Is this possible with Linq?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
That depends.
Do you have a list of objects of different types, where ConfigEntity and DefinitionEntity both inherit from GroupEntity ?
class GroupEntity { }
class ConfigEntity : GroupEntity { }
class DefinitionEntity : GroupEntity { } Or do you have a serialized object graph, where a GroupEntity contains one or more ConfigEntity objects, each of which contains one or more DefinitionEntity objects?
class GroupEntity
{
public List<ConfigEntity> ConfigEntities { get; }
}
class ConfigEntity
{
public List<DefinitionEntity> DefinitionEntities { get; }
}
class DefinitionEntity { } If it's the former, then OfType will do the trick:
public class Parser<T> where T : GroupEntity
{
public List<T> Data { get; set; }
public void LoadDataFromFile(string fileName)
{
List<GroupEntity> allData = Serialization.DeSerializeObject<List<GroupEntity>>(fileName);
Data = allData.OfType<T>().ToList();
}
} If it's the latter, then you're going to need conditional code for each type.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
1) They all individually inherit from EntityBase
2) I have a serialized object graph
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
The problem I see is that there's no way to make the Data property generic.
I can get all of the types like this:
private void LoadDataFromFile(string fileName)
{
try
{
List<RuleGroupEntity> groups = new List<RuleGroupEntity>();
List<RuleConfigurationEntity> configs = new List<RuleConfigurationEntity>();
List<RuleDefinitionEntity> definitions = new List<RuleDefinitionEntity>();
groups = Serialization.DeSerializeObject<List<RuleGroupEntity>>(fileName);
foreach (var group in groups)
{
configs.AddRange(group.RuleConfigurations);
foreach (var config in group.RuleConfigurations)
{
definitions.Add(config.RuleDefinition);
}
}
Type parameterType = typeof(T);
if (parameterType == typeof(RuleConfigurationEntity))
{
Data = (T)Activator.CreateInstance(typeof(T), configs);
}
}
catch (Exception e)
{
}
}
But I then need to assign one of those lists to Data T. Not sure how to convert that.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Something like this should work:
public class Parser<T> where T : EntityBase
{
public List<T> Data { get; set; }
public void LoadDataFromFile(string fileName)
{
List<RuleGroupEntity> groups = Serialization.DeSerializeObject<List<RuleGroupEntity>>(fileName);
switch (typeof(T))
{
case typeof(RuleGroupEntity):
{
Data = (List<T>)(object)groups;
break;
}
case typeof(RuleConfigurationEntity):
{
List<RuleConfigurationEntity> configs = groups.SelectMany(g => g.RuleConfigurations).ToList();
Data = (List<T>)(object)configs;
break;
}
case typeof(RuleDefinitionEntity):
{
List<RuleDefinitionEntity> definitions = groups.SelectMany(g => g.RuleConfigurations).Select(c => c.RuleDefinition).ToList();
Data = (List<T>)(object)definitions;
break;
}
default:
{
throw new NotSupportedException($"Type '{typeof(T)}' is not supported.");
}
}
}
} However, I'm never entirely convinced by a generic type which switches on the type parameter. Perhaps you could use specific parser types instead?
public abstract class Parser<T> where T : EntityBase
{
public List<T> Data { get; set; }
public void LoadDataFromFile(string fileName)
{
List<RuleGroupEntity> groups = Serialization.DeSerializeObject<List<RuleGroupEntity>>(fileName);
LoadDataFromGroups(groups);
}
protected abstract void LoadDataFromGroups(List<RuleGroupEntity> groups);
}
public class RuleGroupEntityParser : Parser<RuleGroupEntity>
{
protected override void LoadDataFromGroups(List<RuleGroupEntity> groups)
{
Data = groups;
}
}
public class RuleConfigurationEntityParser : Parser<RuleConfigurationEntity>
{
protected override void LoadDataFromGroups(List<RuleGroupEntity> groups)
{
Data = groups.SelectMany(g => g.RuleConfigurations).ToList();
}
}
public class RuleDefinitionEntityParser : Parser<RuleDefinitionEntity>
{
protected override void LoadDataFromGroups(List<RuleGroupEntity> groups)
{
Data = groups.SelectMany(g => g.RuleConfigurations).Select(c => c.RuleDefinition).ToList();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
OK, so I implemented your first code snippet. It works.
What I left out before was that this all goes in a repository. I currently have a MongoDB repo, and now I'm implementing the IRepository interface to deal with the serialized version of the data. Now I have a new issue:
This Works
public T Get(Guid id)
{
return Data.Where(x => x.Id == id).FirstOrDefault();
}
This Doesn't Compile
public T Get(Expression<Func<T, bool>> predicate)
{
return Data.Where(predicate).FirstOrDefault();
}
The error is "'List<t>' does not contain a definition for 'Where' and the best extension method overload 'Queryable.Where<t>(IQueryable<t>, Expression<func<t, bool="">>)' requires a receiver of type 'IQueryable<t>'"
The problem is that List<t> isn't an IQueryable. If I change method signaature to accept a delegate instead of an expression, it works.
public T Get(Func<T, bool> predicate)
{
return Data.Where(predicate).FirstOrDefault();
}
I could add this method to the interface, but I'd rather not change existing code if I don't have to. And it causes abiguity beetween the two Get methods.
I'd like to hear your thoughts on this. And thanks for your help so far.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|