Problem in appending a string to a already filled string builder(at the beginning by using INSERT) and then converting that to string array(C#3.0)


I have a string builder like


StringBuilder sb = new
StringBuilder("Value1");
sb.AppendLine("Value2");
/>

Now I have a string say


string str = "value
0";

I did


sb.Insert(0,str); />

and then


string[] strArr =
sb.ToString().Trim().Replace("
", string.Empty).Split(' />');

The result I am getting as (Array size of 2
where I should get 3)


[0] value 0 Value1
[1]
value2

But the desired output being


<

How to insert a string enclosed with double quotes in the beginning
of the StringBuilder and String?


Eg:

/>StringBuilder _sb = new StringBuilder("Sam");
/>

I need to insert the string "Hello" to the beginning of "Sam" and
O/p is "Hello Sam".


String _s = "Jam";
/>

I need to insert the string "Hello" to the beginning of "Jam" and
O/p is "Hello Jam".


How to achieve this?

Programming Languages

I have a string builder like


StringBuilder sb = new
StringBuilder("Value1");
sb.AppendLine("Value2");
/>

Now I have a string say


string str = "value
0";

I did


sb.Insert(0,str); />

and then


string[] strArr =
sb.ToString().Trim().Replace("
", string.Empty).Split(' />');

The result I am getting as (Array size of 2
where I should get 3)


[0] value 0 Value1
[1]
value2

But the desired output being


<
Programming Languages

Is it possible to add a string to beginning of String array without
iterating the entire array.

Programming Languages
I have a RadComoboBox with check boxes and I want to loop through the
check boxes with String Builder. After getting the values in that
format: {1,2,3,4} I want to convert it to stringArray in that format
(1,2,3,4)Can anyone please show me how I can do this?This is my
code:Dim sbPeopleTypes As New StringBuilder()Dim colGroups As IList(Of
RadComboBoxItem) = rcbFilterPersonType.CheckedItemsFor Each item As
RadComboBoxItem In colGroups sbPeopleTypes.Append(item.Value +
",")Nextaspx
VB & VBnet
I will need to Convert std::string to byte array without converting to
System::String.
Seems that both
1) Marshal
2) Ascii -
> Getbytes
will require me to convert std:: string to
System::String.
Is there any functions or class which I can
use.
Thank you very much for your advice.
Programming Languages

The problem I'm having is prompting the user to enter whatever item
appears on the console window and I have to then check if that string
is valid. If it's valid, I have to then append that string, display
all the items that appear in the player's inventory and deduct the
player's money accordingly.



The problem starts at the playerInput function.



#include <iostream>
#include <iomanip>
#include <cctype>
#include <string>
#include <algorithm>

using namespace std;

const int items = 5;
const string ShopInventory[items] = {"Helms", "Boots", "Swords",
"Axes", "Leather Armors"};
const int ItemPrices[items]= {10, 5, 20, 30, 50};

void PrintShop();
int PlayerInput(string [], int&);

int main()
{
string PlayerInventory[items];
int playerMoney = 100;
char Response;

cout << " Welcome traveler to my lovely shop.
";

cout << "
Feel free to browse many of the wonderful items within";
cout << " this store. " << endl;

PrintShop();

while(toupper(Response) != 'N')
{
cout << PlayerInput(PlayerInventory, playerMoney);

cout << "
Is there anything else that you would like to buy? ";
cout << "Enter n or N to quit.
Else enter y or Y to continue. ";
cin >> Response;

while(toupper(Response) != 'Y' && toupper(Response) !=
'N')
{
cerr << "
Sorry, wrong input. Please try again. ";
cin >> Response;
}
}

return 0;
}

void PrintShop()
{
cout << endl;

cout << " ***** Shop Inventory ***** " << endl
<< endl;

cout << "Shop items " << " Price Per Item. " <<
endl << endl;

for(int i=0; i<items; i++)
{
cout << i+1 << ".) " << left << setw(22)
<< ShopInventory[i];
cout << left << setw(3) << ItemPrices[i]
<< " Gold" << endl;
}
}

int PlayerInput(string PlayerInventory[], int &playerMoney)
{
string input;

cout << "
Enter what you would like to buy. ";
getline(cin, input);

while(find(begin(ShopInventory), end(ShopInventory), input) ==
end(ShopInventory))
{
cout << "
The item that you enter isn't in my inventory. ";
getline(cin, input);
}

return playerMoney;
}
Web Development

- Technology - Languages
+ Webmasters
+ Development
+ Development Tools
+ Internet
+ Mobile Programming
+ Linux
+ Unix
+ Apple
+ Ubuntu
+ Mobile & Tablets
+ Databases
+ Android
+ Network & Servers
+ Operating Systems
+ Coding
+ Design Software
+ Web Development
+ Game Development
+ Access
+ Excel
+ Web Design
+ Web Hosting
+ Web Site Reviews
+ Domain Name
+ Information Security
+ Software
+ Computers
+ Electronics
+ Hardware
+ Windows
+ PHP
+ ASP/ASP.Net
+ C/C++/C#
+ VB/VB.Net
+ JAVA
+ Javascript
+ Programming
Privacy Policy - Copyrights Notice - Feedback - Report Violation 2018 © BigHow