I have a string that is like below.
,liger, unicorn, snipe
in other languages I'm familiar with I can just do a string.trim(",") but how can I do that in c#?
Thanks.
There's been a lot of back and forth about the StartTrim function. As several have pointed out, the StartTrim doesn't affect the primary variable. However, given th...
Looking for the best pseudo-code to generate a relative date string (ex. 'asked 1 minute ago', 'asked 2 days ago', 'asked 3 weeks ago', 'asked 4 months ago'...).
Currently implementing this myself and thought it would be a good programming exercise for those that have not tried this before.
Ryan
Edit: I did search before posting and ...
If I am given a MemoryStream that I know has been populated with a String, how do I get a String back out?
...
I have a code snippet written in PHP that pulls a block of text from a database and sends it out to a widget on a webpage. The original block of text can be a lengthy article or a short sentence or two; but for this widget I can't display more than, say, 200 characters. I could use substr() to chop off the text at 200 chars, but the re...
Iterate over and check the byte value of every character in a string - VBA
Code I have:
cell_val = CStr(Nz(fld.value, ""))
Dim iter As Long
For iter = 0 To Len(cell_val) - 1 Step 1
If Asc(Mid(cell_val, iter, 1)) > 127 Then
addlog "Export contains ascii character > 127"
End If
...
For a situation like capturing text incrementally, for example if you were receiving all of the output.write calls when a page was rendering, and those were being appended into a textwriter over a stringbuilder.
Is there a more efficient way to do this? Something that exists in dotnet already preferably? Especially if there's a total si...
Hello,
I'd like to add a method AddDefaultNamespace() to the String class in Java so that I can type "myString".AddDefaultNamespace() instead of DEFAULTNAMESPACE + "myString", to obtain something like "MyDefaultNameSpace.myString". I don't want to add another derived class either (PrefixedString for example).
Maybe the approach is not ...
I have xml where some of the element values are unicode characters. Is it possible to represent this in an ANSI encoding?
E.g.
<?xml version="1.0" encoding="utf-8"?>
<xml>
<value>受</value>
</xml>
to
<?xml version="1.0" encoding="Windows-1252"?>
<xml>
<value>殘</value>
</xml>
I deserialize the XML and then attempt to serializ...
In php I have open a .php file and want to evaluate certain lines. Specifically when the $table_id and $line variables are assigned a value.
Within the text file I have:
...
$table_id = 'crs_class'; // table name
$screen = 'crs_class.detail.screen.inc'; // file identifying screen structure
...
amongst other l...
There are similar question, but not regarding C# libraries I can use in my source code.
Thank you all for your help.
I've already saw lucene, but I need something more easy to search for similar strings and without the overhead of the indexing part.
The answer I marked has got two very easy algorithms, and one uses LINQ too, so it's p...
I have a string coming from a table like "can no pay{1},as your payment{2}due on {3}". I want to replace {1} with some value , {2} with some value and {3} with some value .
Is it Possible to replace all 3 in one replace function ? or is there any way I can directly write query and get replaced value ? I want to replace these strings i...
Say I have 2 strings,
String s1 = "AbBaCca";
String s2 = "bac";
I want to preform a check returning that s2 is contained within s1. I can do this with:
return s1.contains(s2);
I am pretty sure that contains() is case sensitive, however I can't determine this for sure from reading the documentation. If it is then I suppose my best m...
Learning to program, trying to do this
I have a string like this
2+24*48/32
and I want to split it into a list like this
['2', '+', '24', '*', '48', '/', '32']
I have messed around with .split() but that's messy as it returns a list, which means I would now have to iterate over two strings, etc
...
I have 2 strings that I'd like to compare, and return the positions of the different characters in the second string. For instance, if I have
1. "The brown fox jumps over the lazy dog" and
2. "The quick brown fox jumped over the lazy dog",
I want it to highlight "quick" and "ed". What's the best way to go about this in PHP?
...
I know how to do this if I iterate through all of the characters in the string but I am looking for a more elegant method.
Thanks
...
I'm a little confused about how the standard library will behave now that Python (from 3.0) is unicode-based. Will modules such as CGI and urllib use unicode strings or will they use the new 'bytes' type and just provide encoded data?
...
How can brackets be escaped in a C# format string so, something like :
String val = "1,2,3"
String.Format(" foo {{0}}", val);
doesn't throw a parse exception but actually outputs the string " foo {1,2,3}"
Is there a way to escape the brackets or should a workaround be used.
...
I've not used C++ very much in the past, and have recently been doing a lot of C#, and I'm really struggling to get back into the basics of C++ again. This is particularly tricky as work mandates that none of the most handy C++ constructs can be used, so all strings must be char *'s, and there is no provision for STL lists.
What I'm cur...
I have an algorithm that generates strings based on a list of input words. How do I separate only the strings that sounds like English words? ie. discard RDLO while keeping LORD.
EDIT: To clarify, they do not need to be actual words in the dictionary. They just need to sound like English. For example KEAL would be accepted.
...
I use to run
$s =~ s/[^[:print:]]//g;
on Perl to get rid of non printable characters.
In Python there's no POSIX regex classes, and I can't write [:print:] having it mean what I want. I know of no way in Python to detect if a character is printable or not.
What would you do?
EDIT: It has to support Unicode characters as well. Th...