I am thinking of doing this way:
List sList = new ArrayList();
// Add elements.
if (sList != null)
{
String listString = sList.toString;
listString = listString.subString(1, listString.length() - 1);
}
I somehow found this to be neater than using the StringBuilder/StringBuffer approach.
Any tho...
hello
how can I replace 2 strings in the same time? for example let's say I have string like this:
str1 = "AAAA BBBB CCCC DDDD"
i want to replace every "AAAA" with "CCCC" and every "CCCC" with "AAAA" but if i did:
str1.gsub("AAAA","CCCC") # CCCC BBBB CCCC DDDD
str1.gsub("CCCC","AAAA") # AAAA BBBB AAAA DDDD
what I want str1 to be "C...
I'm doing something really simple: slurping an entire text file from disk into a std::string. My current code basically does this:
std::ifstream f(filename);
return std::string(std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>());
It's very unlikely that this will ever have any kind of performance impact on the program...
Hi guys, I've got a tricky problem that I need some help with.
Currently, I have a file with about 100 #defines in it, from 1-100, and each with a unique string value.
Now I'm trying to print this value, but instead of the value, I want to print what the #define is. For example:
#define FIRST_VALUE 1
var = FIRST_VALUE;
printf("%s", va...
What is the best way to remove all the special characters from a string - like these:
!@#$%^&*(){}|:"?><,./;'[]\=-
The items having these characters removed would rather short, so would it be better to use REGEX on each or just use string manipulation?
Thx
Environment == C#/.NET
...
I have a PHP function that I'm using to output a standard block of HTML. It currently looks like this:
<?php function TestBlockHTML ($replStr) { ?>
<html>
<body><h1> <?php echo ($replStr) ?> </h1>
</html>
<?php } ?>
I want to return (rather than echo) the HTML inside the function. Is there any way to do this without build...
I'm creating a big string that ends up getting sent out via email. The string is created as follows:
For Each NewClaim As BO.ClaimsByPECLogIDRO In NewClaims
strNewClaims &= Environment.NewLine & NewClaim.ClaimPrefix.ToString _
& "-" & NewClaim.ClaimNumber.ToString & " - " & NewClaim.ReportDate.To...
In python, what does the 2nd % signifies?
print "%s" % ( i )
...
Suppose I have an object representing a person, with getter and setter methods for the person's email address. The setter method definition might look something like this:
setEmailAddress(String emailAddress)
{
this.emailAddress = emailAddress;
}
Calling person.setEmailAddress(0), then, would generate a type error, but cal...
Hi,
In a dictionary like this:
Dictionary<string, string> openWith = new Dictionary<string, string>();
openWith.Add("txt", "notepad.exe");
openWith.Add("bmp", "paint.exe");
openWith.Add("dib", "paint.exe");
openWith.Add("rtf", "wordpad.exe");
Console.WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]);
The output is:
...
Hey all. I want to use print to print hex numbers in the form 0x###, but if the number is 0, I want to omit the 0x part. How can I do this?
Thanks!
...
While debugging a program in XCode I have several CFStringRef variables that point to strings with lengths around the 200 character mark.
In the debugger, it only shows the value of these strings up to a certain length and then just ellipses them away. I'd really like to see the full value of the strings.
Is there some option I can con...
Does anyone know how text editors/programmers editors are able to do such fast searches on very large text files.
Are they indexing on load, at the start of the find or some other clever technique?
I desperately need a faster implementation of what I have which is a desperately slow walk from top to bottom of the text.
Any ideas are r...
Suppose I have a string, for example,
string snip = "</li></ul>";
I want to basically write it multiple times, depending on some integer value.
string snip = "</li></ul>";
int multiplier = 2;
// TODO: magic code to do this
// snip * multiplier = "</li></ul></li></ul>";
EDIT:
I know I can easily write my own function to impleme...
hi,
I have following questions regarding strings in C++
1>> which is a better option(considering performance) and why?
1.
string a;
a = "hello!";
OR
2.
string *a;
a = new string("hello!");
...
delete(a);
2>>
string a;
a = "less";
a = "moreeeeeee";
how exactly memory management is handled in c++ when a bigger string is copie...
Is there an inbuilt PHP function to replace multiple values inside a string with an array that dictates exactly what is replaced with what?
For example:
$searchreplace_array = Array('blah' => 'bleh', 'blarh' => 'blerh');
$string = 'blah blarh bleh bleh blarh';
And the resulting would be: 'bleh blerh bleh bleh blerh'.
...
Hi,
I'm looking for a simple java lib/src to highlight differences between two Strings, case-sensitive. A html output would be great, but I would be happy to get the indexes of the diffs, something like:
diff("abcd","aacd")
> [2,2]
diff("maniac", "brainiac")
> ["man",brain"] or [0,3] or something like that
The idea is to higlight ty...
I have a java string, which has a variable length.
I need to put the piece "<br>" into the string, say each 10 characters.
For example this is my string:
`this is my string which I need to modify...I love stackoverlow:)`
How can I obtain this string?:
`this is my<br> string wh<br>ich I nee<br>d to modif<br>y...I love<br> stackove...
In a C++ MD2 file loader, I have a lot of frames, each with a name that ends with a number, such as
stand0
stand1
stand2
stand3
stand4
...
stand10
stand11
run0
run1
run2
etc.
How do I get what the string is without the number behind? e.g. a function that changed "stand10" to just "stand"
...
In C++, I could do:
for(int i = 0; i < str.length(); ++i)
std::cout << str[i] << std::endl;
How do I iterate over a string in Python?
...