Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8610679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:11:21+00:00 2026-06-12T04:11:21+00:00

I have a function in c# that used to manipulate the string, It works

  • 0

I have a function in c# that used to manipulate the string, It works well while I used in C#. Now I want to convert this function to use in JavaScript. This is the function in C#:

 public static string TrimString(string str, int lenght)
 {
        string _str = str;

        int _iAdditionalLenght = 0;

        for (int i = lenght; i < str.Length; i++)
        {
            if (_str.Substring(i, 1) == " ")
                break;

            _iAdditionalLenght++;
        }

        return str.Substring(0, str.Length < (lenght + _iAdditionalLenght) ? str.Length : (lenght + _iAdditionalLenght));

 }

I converted it to javascript :

function TrimString(str, lengthStr) { //this is my testing 4
     var _str = str;
     var _iAdditionalLenght = 0;
     for (var i = lengthStr; i < str.length; i++) {
       if (_str.substring(i, 1) == " ")
           break;
       _iAdditionalLenght++;
     }

     return str.substring(0, str.length < (lengthStr + _iAdditionalLenght) ? str.length : (lengthStr + _iAdditionalLenght));
 }

But the javascript doesn’t work.

Could anyone tell me, how could I do it in JavaScript function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:11:22+00:00Added an answer on June 12, 2026 at 4:11 am

    substring differs between C# & javascript

    Eg., strInput = “0123456789”

    In C# ==> Substring(int startIndex, int length)

         strInput.SubString(2,3) == will output ==> "234"
    

    In Javascript ==> substring(int startIndex, int endIndex)

         strInput.substring(2,3) == will output ==> "2"
    

    instread try to use

         strInput.substr(2,3) == will output ==> "234"
    

    Note :

    in javscript

         substring(Start character position, End Character position) 
    
         substr(Start character position, length of Character) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one javascript function that used to display the menu and content in
Right now I have a function, in a class that is used to listen
In an external javascript file I have a function that is used to append
I have a function that is used to creating a directory. It uses CreateDirectoryA()
I have a function that I have used a bunch of times in various
I have a function in java script, that I used it to take the
I am not used to manipulate bytes in my code and I have this
I have a function that can be used to redirect the user to different
I have a handy function that I've used in Java for converting an InputStream
I have used DLL Export viewer to try and find the functions that are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.