|
hi,
i am beginner in c#, i need tour help, i want two break textbox text in two part
For example
textbox1.text = "ABT-001"
ABT-001 break into "ABT-00" and "1"
textbox2.text = "ABT-00" and textbox3.text="1"
Hope you understand by question
Thanks
|
|
|
|
|
You are looking for the String.Substring method[^]
What it does it returns a new string, cut down from the original. You just have to specify the start position of the new string (in characters from the beginning of the original) and the length of the new string, in characters:
int len = textBox1.Text.Length;
textbox2.Text = textBox1.Text.Substring(0, len - 1);
textbox3.text = textbox1.Text.Substring(len - 1); (if you don't specify the length, you get the whole remaining string).
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Why would anyone vote you down for that?
Beginners have to start somewhere, and English isn't everybody's native language.
Compensated.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
OriginalGriff wrote: Why would anyone vote you down for that?
A trend that seems to be increasingly common. There are obviously a (I hope small) number of people whose only contribution to CodeProject is to down vote those questions they deem unworthy. I guess in a population this size there will always be a percentage of morons.
I must get a clever new signature for 2011.
|
|
|
|
|
Richard MacCutchan wrote: morons.
I can think of another word which fits them better. Starts with "A"...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Assets ?
I know the language. I've read a book. - _Madmatt
Two letters away from being an asset
|
|
|
|
|
Close enough!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Amazing - you got downvoted!
Compensated.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
|
|
|
|
|
Now, I wonder who did that? Was it an As...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
What pattern do you want to use to break the text apart? Do you want to break it based on the length? Is it based on a particular string pattern, e.g. XXX-NN representing the first part? Before anybody can offer you a definitive answer, you need to explain the problem fully.
|
|
|
|
|
|
Hi everybody
i'm in very bad situation cause i can't find a way to get url of a current tab in Chrome...
i found a part of code but it doesn't work anyway ....
[DllImport("user32")]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg,
IntPtr wParam, StringBuilder lParam);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr parentHandle,
IntPtr childAfter, string className, IntPtr windowTitle);
private const int WM_GETTEXT = 0x000D;
public static string getChromeURL()
{
uint MAX_PATH = 255;
IntPtr hChrome, hAddressBox;
hChrome = GetForegroundWindow();
hAddressBox = FindWindowEx(hChrome, IntPtr.Zero,
"Chrome_AutocompleteEditView", IntPtr.Zero);
StringBuilder sb = new StringBuilder(256);
SendMessage(hAddressBox, WM_GETTEXT, (IntPtr)MAX_PATH, sb);
string s = sb.ToString().Trim(new Char[] { ' ', '\0', '\n' });
return s;
}
i don't know what i messed in this code . but it doesn't work for me
so please HELP ME .............
|
|
|
|
|
Hi,
welcome to CodeProject. You managed to ask a clear question with a readable code snippet, using PRE tags. Very good. You did fail to provide details on the failure though, if there is a compile-time or run-time error message/exception, you should report it.
It so happens I think I know what is going on: when sending messages to another process, if a pointer is involved, then that pointer must be valid in the destination process, not the originating process. So you need a buffer in the destination process, then request the data gets put into that buffer, and then you can go and read from that buffer. This takes several Win32 functions, I have an example (and an LP_Process class) here: LP#TrayIconBuster[^]. I suggest you study it there.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Luc Pattyn wrote: You managed to ask a clear question with a readable code snippet, using PRE tags.
and it wasn't marked as URGENTZ
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
In fact I haven't seen an urgentz anything for months now, not sure what is going on. Some winter effect maybe? Or have they all migrated to Q&A (I wouldn't notice nor mind)?
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Luc Pattyn wrote: I haven't seen an urgentz anything for months now
Are you sure you've been visiting the REAL Code Project site, or do you suspect you've been redirected to some hacked copy of the site?
|
|
|
|
|
|
He's just been keeping his eyes shut.
|
|
|
|
|
wide shut probably.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
thanks for your answer
i don't have anay bug with this code but when i run it the return value of getChromeURL is null i don't know why !!!!
PS: great article
|
|
|
|
|
you're welcome.
moums wrote: the return value of getChromeURL is null i don't know why
if you read the article you should know by now. If it still fails, you should compare what you have with what I offered, and if that doesn't help, you might post the relevant part of your code here.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
wooooooooooooow it's working now
thx a lot Luc for everything .............
see u nxt..... may be for an other question
take care...
|
|
|
|
|
Good observation Luc. Moreover the OP is responding to the replies. Not like "fire and forget" way.
|
|
|
|
|
I searched and found this post, but if I understand this correctly it will not work in my situation
http://www.codeproject.com/Messages/1907458/Re-Big-html-string-How-to-store-them.aspx[^]
How can I set a long string with multiple quotes inside of it to a single string variable? I want to hard code this so I can do a string replace. Thanks for reading!
An example would be
string htmltoreplace1 = @"<img src="/_layouts/images/blank.gif" class="ms-hidden" border=0 width=1 height=1 alt="Use SHIFT+ENTER to open the menu (new window)."></A><IMG SRC="/_layouts/images/blank.gif" ALT="" BORDER=0><IMG SRC="/_layouts/images/blank.gif" BORDER=0 ALT=""></TD><TD style="position:absolute;"><IMG src="/_layouts/images/blank.gif" width=13px style="visibility: hidden" alt="">"
or
string htmltoreplace2 = @" <TABLE width="100%" cellspacing=0 cellpadding=0 border=0><SCRIPT>
ctx = new ContextInfo();
ctx.listBaseType = 0;
ctx.listTemplate = 100;
ctx.listName = "{5B7B0FEE-FE98-4066-A4FB-F48DF04D4EBA}";
ctx.view = "{79DA2D89-70D6-4497-90D9-DDE74040EF88}";
ctx.listUrlDir = "\u002fdcs\u002fotso\u002fDSUSF\u002fISSBR\u002fdeddDIB\u002fws\u002fLists";
ctx.HttpPath = "\u002fdcs\u002fotso\u002fDSUSF\u002fISSBR\u002feDIB\u002fws\u002f_vti_bin\CS=65001";
ctx.HttpRoot = "http:\u002f\u002.comb\u002fdcs\u002fotso\u002fDSUSF\u002fISSBR\u002fddeDIB\u002fws";
ctx.imagesPath = "\u002f_layouts\u002fimages\u002f";
ctx.PortalUrl = "http:\u002f\u002.com\u002fdcs\u002f";
ctx.SendToLocationName = "";
ctx.SendToLocationUrl = "";
ctx.RecycleBinEnabled = -1;
ctx.OfficialFileName = "";
ctx.WriteSecurity = "1";
ctx.SiteTitle = "Windows Support";
ctx.ListTitle = "Windows Shift Rotation";
if (ctx.PortalUrl == "") ctx.PortalUrl = null;
ctx.displayFormUrl = "\u002fdcs\u002fotso\u002fDSUSF\u002fISSBR\u002fdeddbDIB\u002fws\u002fLists\u002fDispForm.aspx";
ctx.editFormUrl = "\u002fdcs\u002fotso\u002fDSUSF\u002fISSBR\u002feDIB\u002fws\u002fEditForm.aspx";
ctx.isWebEditorPreview = 0;
ctx.ctxId = 3;
g_ViewIdToViewCounterMap[ "{79DA2D89-70D6-4497-90D9-DDE74040EF88}" ]= 3;
ctx.CurrentUserId = 9341;
ctx3 = ctx;
</SCRIPT>"
modified on Friday, January 28, 2011 1:39 PM
|
|
|
|
|
use the backslash:
string str = "This is a string with \"quotes\" in it";
the other option is to "double up" the quotes and use the @ modifier
string str2 = @"This is a string with ""quotes"" in it";
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|