|
how bout a function along the lines of the following
string MergeFunction(string value)
{
result = value;
for(int i = 0; i < value.length; i++)
{
if(value[i-1] == ' ' && value[i+1] == ' ')
{
result = result.remove(i+1, 1);
}
}
return result;
}
dont forget you also need to include some check for handling if i == 0; or i == value.length -1;
because it will throw a index out of bounds error as it is.
EDIT: oops you will need some sort of count for the number of spaces currently remove so you can subtract it from the value when using result.remove
result.remove(i+1-count, 1);
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
can u give me the entire code with my given input.... pls...
it shows out of bound error even i do as u said...
pls help me out
the quieter u become more u hear
|
|
|
|
|
Ok as its not too much code, though im not testing so let me know any errors
string MergeFunction(string s)
{
string result = s;
int count 0;
for(int i = 0; i < s.Length-1; i++)
{
if(i == 0)
{
if(s[i+1] == ' ')
{
result = result.Remove(i+1-count, 1);
count++;
}
}
else
{
if(s[i-1] == ' ' && s[i+1] == ' ')
{
result = result.Remove(i+1-count, 1);
count++;
}
}
}
return result;
}
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
using System;
using System.Collections;
class chapter10
{
static void Main()
{
string result = "s y t y i";
int count= 0;
for(int i = 0; i < result.Length-1; i++)
{
if(i == 0)
{
if (result[i + 1] == ' ')
{
result = result.Remove(i+1-count, 1);
count++;
}
}
else
{
if (result[i - 1] == ' ' && result[i + 1] == ' ')
{
result = result.Remove(i+1-count, 1);
count++;
}
}
}
Console.WriteLine( result);
}
}</summary></summary>
this is my modified code.... but it checks only first and second char....wat should i do now.... pls specify changes alone in bold letter...
thanks u very much for ur help
the quieter u become more u hear
|
|
|
|
|
lawrenceinba wrote: string result = "s y t y i";
Should be :-
string s = "s y t y i";//you need an original instance, not just the result instance
string result = s;
lawrenceinba wrote: if (result[i + 1] == ' ')//check if next char is a space
Should be :- s[i + 1] == ' '
lawrenceinba wrote: if (result[i - 1] == ' ' && result[i + 1] == ' ')//
Should be :- s[i - 1] == ' ' && s[i + 1] == ' '
but please make it a seperate function and call it from within your main, its much better practise i.e.
string result = MergeFunction("s y t y i");
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
There's a one-liner for everyting.
text = Regex.Replace(text, @"\b([^ ]) (?=[^ ]\b)", "$1");
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
input= " s y t b/d y i yt"
according to ur code it give out sytb/d yi yt
only single characters should be joined what should i do now
if it has any delimiters it should not be joined... delimiters are (!#&*;/)
thanks
the quieter u become more u hear
|
|
|
|
|
Use a positive lookbehind to match a space of the beginning of the string followed by a non-space character, and look for a space or the end of the string instead of the word boundary in the lookahead.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
ya tat's wat im expecting but how to i do it using regex
for tat i should use for loop.. isn't it..
is there any way in regex
the quieter u become more u hear
|
|
|
|
|
lawrenceinba wrote: ya tat's wat im expecting
wy ar yu takin lik dis?
lawrenceinba wrote: but how to i do it using regex
for tat i should use for loop.. isn't it..
is there any way in regex
Yes, there is. If you do what I already explained, it looks like this:
text = Regex.Replace(text, @"(?<=^| )([^ ]) (?=[^ ](?: |$))", "$1");
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
oops......i'm very sorry... i thought you could understand.....here after i'll type fully...
thanks
the quieter u become more u hear
|
|
|
|
|
|
You have to define what you expect to happen, you change it all the time. You started off with merging single characters, and now you want to separate words by inserting extra spaces also...
For example, how should the delimiters work? Should a space be added after each delimiter, and should that happen all the time or only if there is a single character after it? Does it matter if that single character will be merged with another single character? If there is a single character before a delimiter, should a space be added, and should that happen only if there is another single character to merge it with?
Also, why do you expect the last character in your example to remain a single character eventhough there is another single character before it to merge it with?
Perhaps you should explain what it is that you are actually going to use it for, instead of making up abstract examples.
Regular expressions can be used to a lot of things, but guessing is not one of them...
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
if a delimter is before or after a single character it also should be merged together.. that's.....
other things i fixed ...
pls send me links regading regular expression symbols...
the quieter u become more u hear
|
|
|
|
|
kindly send me any good link to study about patterning Regex.... what's the meaning for each characters used in that.. so and so... only i need these informations...
general Regex functions and operations i know....
thanks
the quieter u become more u hear
|
|
|
|
|
Hi Expert,
i m new in C#
this is login form.but connection adapter having null value.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace ExampleOne
{
public partial class login : Form
{
public MySqlDataAdapter da;
public DataSet adset;
public string g_login;
public login()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void btnlogin_Click(object sender, EventArgs e)
{
string g_login = this.tbUsername.Text;
string g_password = this.tbpassword.Text;
string MyConString = "server=localhost;database=password;uid=root;password=asd";
MySqlConnection connection = new MySqlConnection(MyConString);
string Strsql = "select * from tablogin where ='"+g_login ;
try
{
connection.Open();
MySqlDataAdapter DA = new MySqlDataAdapter(Strsql, connection);
MySqlCommandBuilder cmdb = new MySqlCommandBuilder(da);
DA.Fill(adset, "tablogin");
DataColumn[] key = new DataColumn[1];
key[0] = adset.Tables["tablogin"].Columns["password"];
adset.Tables["tablogin"].PrimaryKey = key;
DataRow dr = adset.Tables["tablogin"].Rows.Find(g_password);
if ((g_login == dr["userid"].ToString()) && (g_password == dr["password"].ToString()))
{
MessageBox.Show("You are logged in!","welcome",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show("You entered wrong Username or Password","Warning",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
Console.WriteLine("Error Conecting to database", "window information" + ex.Message.ToString(),
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void Close_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("Are you sure to Exit ?","finish" ,MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
Application.Exit();
}
}
}
}
|
|
|
|
|
i've got a font wich is mentioned true type.when i tried to set this font to combobox i get the error saying this is not a true type font . how can i set this font to the cmbbox.do i have any solution .intead of going to some other font .
|
|
|
|
|
Can someone please guide me in finding a working solution of reading a .mpp file in C#, I have a sample .mpp file from MS Project 2003, i don't have MS Project application installed, so i am not able to find the OLEDB drivers 9.0,11.0 or anything like that to download or install on my PC, kindly help...
would just like to mention that i have already have gone through a lot of articles and sample, but they all seem to have the dll, which possibly means that the application would be installed which is not the case here... help needed asap
|
|
|
|
|
Hey everbody
I have a big problem to upload one csv fil to mysql database.
i have a big csv file with many records and column
Eks.:
ArticleNo ManArticleNo DescShort DescLong Manufacturer Price Stock
642 0993A001 BJ-642/black 790sh f BJ300 330 Canon blækpatron, sort (BJI-642BK) Canon 97,11 0
665 1009A001 BJC-643/black f BJC-800 820 880 Canon blækpatron, sort (BJI-643BK) Canon 157,43 0
673 1012A001 BJC-643/yellow f BJC-800 820 880 Canon blækpatron, gul (BJI-643Y) Canon 203,42 0
3131 51604A HP Ink Cart/Black f ThJet QJet+ f plain HP blækpatron, sort (CJ-3A) Hewlett Packard 57,91 115
3135 51605R HP Ink cart/red f Think- Quietjet HP blækpatron til ThinkJet/QuietJet, magenta Hewlett Packard 63,63 0
i load the file like this
StreamReader input = new StreamReader(@"c:\test.csv");
string inputLine = "";
while ((inputLine = input.ReadLine()) != null)
{
but now i need just to take ManArticleNo and Price from the inputLine
my input line has all the row, how can i split or somthing to take just that column i need ?
string tr = inputLine.?(?);
}
input.Close();
|
|
|
|
|
string[] columns = inputLine.Split(',');
then you just reference the index of the columns you want e.g.
string ManArticleNo = columns[0];
then you do the database update stuff
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
you are the man
|
|
|
|
|
hi,
I have created Excel-RTD server in C#. like this article
http://weblogs.asp.net/kennykerr/archive/2008/11/13/Rtd3.aspx[^]
Here data is populating randomly in excel file.
I will start RTD Server from different project (like button clik) :- able to start successfully
and i want to send/update data to rtd server from other project. :- object used by RTD sever has no value, it is worked altogether in different thread.
Thanks
hiren shah
hirenkshah@gmail.com
|
|
|
|
|
That's great.
Regards,
Rob Philpott.
|
|
|
|
|
Hi,
I have a data grid control and I placed one combo box in that data grid and I am binding data to data grid combo box.When i run the application by default the combo box is not showing anything if i double click on combo box then only it is displaying the items. Can anybody please help me to resolve the problem showing combo box items in data grid control by default when i run the application.
Thanks in Advance
Pavani
|
|
|
|
|
Hi, I want to give a value in a textbox when the 'tab' key is pressed in another textbox. My code is this:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if ( (e.KeyChar.Equals(('\t'))) || (e.KeyChar.Equals(Keys.Tab)) ){
this.textBox2.Text = "hola";
}
}
But the only way that it works is to set the 'Multiline' and 'AcceptsTab' properties to be true (both properties at the same time, unless it not works). And the problem is that on this way, to press the tab key the focus not change to another textbox.
Anybody knows a better way?
|
|
|
|