string

How can I Trim the leading comma in my string.

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...

Relative date string in pseudocode

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 ...

How do you get a string from a MemoryStream?

If I am given a MemoryStream that I know has been populated with a String, how do I get a String back out? ...

How to Truncate a string in PHP to the word closest to a certain number of characters?

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

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 ...

Is there a more efficient text spooler than TextWriter/StringBuilder

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...

Can I add new methods to the String class in Java?

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 ...

Non-unicode XML representation

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>&#27544;</value> </xml> I deserialize the XML and then attempt to serializ...

strpos function problem in PHP not finding the needle

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...

Are there any Fuzzy Search or String Similarity Functions libraries written for C#?

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...

how to replace multiple strings together in Oracle

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...

Is the Contains Method in java.lang.String Case-sensitive?

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...

How do I split a string into a list Python?

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 ...

How do you find the difference between 2 strings in PHP?

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? ...

In python how to I verify that a string only contains letters, numbers, underscores and dashes?

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 ...

Will everything in the standard library treat strings as unicode in Python 3.0?

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 to escape brackets in a format string in .Net

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. ...

C++ strings without <string> and STL.

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...

How do I determine if a random string sounds like English?

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. ...

Stripping non printable characters from a string in python

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...