remove part of element from object array

ankit goel 766 Reputation points
2022-12-13T14:02:31.577+00:00

@Jack J Jun , I am trying to filter from one the element and remove a part of word from the other elements of object array and add to the list of objects. The word which has been removed should get added to another list (Vintage Flip). Below is the source excel file
270085-image.png

what i want is
270118-image.png

rest of the results are dropped because they are below a certain limit . below is the error that i am getting
270147-query2-13-dec.jpg

but i checked at the element of object array and found that it is in int itself .
270148-query13-query3.jpg

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,495 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jack J Jun 25,296 Reputation points
    2022-12-14T02:51:05.957+00:00

    @ankit goel , Welcome to Microsoft Q&A,

    The error you get means that you could not convert 1 PCS to int type.

    We need to remove the PCS first and then convert string 1 to int 1.

    Here is a code example you could refer to.

     var arr = (object[,])range1.get_Value(XlRangeValueDataType.xlRangeValueDefault);  
      
            for (int i = 1; i <= arr.GetLength(0); i++)  
            {  
                if (arr[i, 1] != null)  
                {  
                    int id = Convert.ToInt32(arr[i, 2].ToString().Replace("PCS", "").Trim());  
                    if(id>30)  
                    {  
                        listnew.Add(new object[] { arr[i, 1] });  
                    }  
                   
      
                }  
            }  
    

    Result:

    270247-image.png

    Hope my code could help you.

    Best Regards,
    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.