简体   繁体   中英

While saving data to mysql from my android app it removes spaces

suppose i have a field in which i will get full_name. so between firstname and lastname there should be a space. but when i enter like -- Tom Cruise ,,, it gives error ,, shows . but it takes TomCruise nicely. here is my code. i also dont have any trim function. so why i can not save white spaces.

activity_main.xml

<TextView
    android:text="full name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

MainActivity.java i am just giving cruicial part.

private EditText editTextName;

 editTextName = (EditText) findViewById(R.id.editTextName);

String name = editTextName.getText().toString();

String urlSuffix = "?name="+name+"&username="+username+"&password="+password+"&email="+email;

i am sending to php site and then save it. works fine if i remove the space between words.

private EditText editTextName;

editTextName = (EditText) findViewById(R.id.editTextName);

String name = editTextName.getText().toString();


String urlSuffix = "?name="+name+"&username="+username+"&password="+password+"&email="+email;

// Spaces are not allowed in urls, to represent it we use %20, add the below line to replace all spaces with "%20".

urlSuffix = urlSuffix.replace(" ", "%20");

Just replace the space character to "%20". name = name.replace(" ","%20");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM