Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I just want to copy this NKJFK-GPHP7 from this post

NKJFK-GPHP7
this can change
????? - ?????
I want to copy like this


What I have tried:

C#
string test = TakePieceFromText("this is my data to work with", 2, 5);

/// <summary>
/// Takes the piece from text.
/// </summary>
/// <param name="text">The text.</param>
/// <param name="startIndex">The start index.</param>
/// <param name="length">The length.</param>
/// <returns>a piece of text</returns>
private string TakePieceFromText(string text, int startIndex, int length)
{
    if (string.IsNullOrEmpty(text))
        throw new ArgumentNullException("?????-?????");

    string result = string.Empty;
    try
    {
        result = text.Substring(startIndex, length);
    }
    catch (Exception ex)
    { 
     // log exception
    }
    return result;
}
Posted
Updated 12-Feb-21 7:56am
v2
Comments
Richard MacCutchan 12-Feb-21 3:32am    
So what is the problem?
CL4Y3R-TR 12-Feb-21 3:42am    
not copying text
CL4Y3R-TR 12-Feb-21 3:44am    
The text I want to copy will constantly change but the format ????? - ????? such
PIEBALDconsult 12-Feb-21 13:57pm    
Regular Expressions.

You can use RegEx, see examples here: https://www.dotnetperls.com/regex[^]

If you have never used RegEx, test first with one of these (online) tools: https://www.slant.co/topics/302/~best-regex-testing-tools[^]

Try:
([0-Z])+-([0-Z])+

and if the number of characters is always the same:
(.....)-(.....)

If you don't like Regex, see this CodeProject article: I don't like Regex...[^]
 
Share this answer
 
v5
Comments
CL4Y3R-TR 12-Feb-21 4:50am    
i dont understand
RickZeeland 12-Feb-21 5:45am    
Then maybe this is more your cup of tea:
https://www.codeproject.com/Articles/368258/I-dont-like-Regex
To add to what RickZeeland says, the regex isn't even complicated:
(?<=")\w+-\w+(?=")
Will do it.
 
Share this answer
 
Comments
CL4Y3R-TR 12-Feb-21 4:51am    
i dont understand sorry
OriginalGriff 12-Feb-21 4:54am    
What part do you not understand?
You know how to use a Regex in your code, yes?
CL4Y3R-TR 12-Feb-21 7:45am    
please can you edit and write
OriginalGriff 12-Feb-21 8:13am    
Edit and write what? Your whole app?
CL4Y3R-TR 19-Feb-21 3:40am    
Can you add it to the code I provided

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900